1. 程式人生 > 實用技巧 >G - Game

G - Game

https://vjudge.net/contest/388843#problem/G

Notice:Don't output extra spaces at the end of one line.

Dodo bird and ddd are playing a stone game on a 2-d plane. There are $n$ points on the plane where they can put the stone. The rule is as follows:

- Before the game start, The stone is at the first point.
- Dodo and ddd move the stone in turn, Dodo moves first.
- In the first move, the player can move the stone to any point except the first point.
- Starting from the second move, assume the stone is currently at point $x$, and the distance of the stone traveled in the last move is $d$. The player can move the stone to a point $y$ if and only if $\text{distance(x,y)} > d$ and point $y$ has never been visited before.
- If a player cannot make a move, he loses the game.

Please determine who will win the game if both player use the best strategy.

InputThe first line contains an integer $T(1 \leq T \leq 100)$, indicating the number of test cases.

Each test case contains several lines. The first line contains an integer $n(2 \leq n \leq 2000)$, indicating the number of points. Next $n$ lines, each line contains two integers $x_i, y_i(-10^9 \leq x, y \leq 10^9)$, indicating the coordinate of the i-th point.


It is guaranteed that there are at most 12 test cases with $n > 500$.
OutputFor each test case, If Dodo can win the game, print "YES". Otherwise, print "NO".Sample Input

2
5
1 1
0 0
2 0
0 2
2 2
4
1 1
0 0
0 2
2 2

Sample Output

NO
YES

Sponsor

題意:
A,B輪流走,每次走的距離比上一次大。走過的點不能再走,不能走的人輸,問先手是否必勝。

思路:

參考https://blog.csdn.net/tomjobs/article/details/107947511

最後走到最遠距離的一對點,一人先走到這些點中行動,另一人就不能再行動了。

最多隻剩下一個最遠點 偶數先手勝

最後只剩下一個點且為點1,1必敗。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl;

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db;

const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=2007;
//const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7;

struct node
{
    ll x , y , d;
};
node A[maxm];
node Path[maxm*maxm];

int v[maxm] = {0};

int cmp(node x,node y)
{
    return x.d < y.d;//遞增 
}
ll D(int i,int j)
{
	int ans = (A[i].x-A[j].x)*(A[i].x-A[j].x)+(A[i].y-A[j].y)*(A[i].y-A[j].y); 
    return ans; 
}
int main() {
    int T = 0;
	cin >> T;
	
    while(T--)
	{
        int n = 0;
		cin >> n;
        for(int i = 0;i<n;i++)
		{
            cin >> A[i+1].x >> A[i+1].y;
            v[i] = 0;
        }
        int L = 0;
        for(int i = 0;i<n;i++)
		{
            for(int j = i;j < n;j++)
			{
				L += 1;
                Path[L].x = i+1;
				Path[L].y = j+1;
				Path[L].d = D(i+1,j+1);
            }
        }
        sort(Path+1,Path+1+L,cmp);
        
        int X = 0;
		int Y = 0;
        for(int i = 0;i<L;i++)
		{
            X = Path[L-i].x;
			Y = Path[L-i].y;
            if(v[X] || v[Y])
            {
            	continue;
			}
			else
			{
                n = n - 2;
                v[X] = 1;
                v[Y] = 1;
            }
        }
        
        if(n == 0)
		{
            cout << "YES" <<endl;
        }
		if(n == 1)
		{
			if(v[1]) cout << "YES" <<endl;
        }
   		if(n !=0 && n != 1) cout << "NO" <<endl;
    }
    return 0;
}