hdu - 6850 Game

Problem Description
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 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.

Input
The first line contains an integer T(1≤T≤100), indicating the number of test cases.

Each test case contains several lines. The first line contains an integer n(2≤n≤2000), indicating the number of points. Next n lines, each line contains two integers xi,yi( − 1 0 9 −10^9 109≤x,y≤ 1 0 9 10^9 109), indicating the coordinate of the i-th point.

It is guaranteed that there are at most 12 test cases with n>500.

Output
For 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

题目给你n个点的坐标,从第一个点出发,两个人轮流移动石子到没有经过的点上,并且从第二次开始每次移动的距离要比上一次大,两个人都按最优方案移动,问先手是否能赢。

若先手能赢,那么后手走到了最大边的其中一个端点上。我们往前推两步,后手走到了一条次大边上,并且这条次大边的两个端点与最大边的两个端点都不同,那么先手走到这条次大边的另外一个端点。此时后手只有两种情况,一种无路可走,一种只能走到最大边的一个端点上。一直往前推,发现会推到后手走到点1的情况。

若后手能赢,那么我们推不到其中一个端点是点1的边,这时先手从点1出发一定会走到上述推到的其中一条边的一段。

由此我们可知,只需要把边的长度从大到小排序,每次把两个端点都没有被访问过的边的端点打上标记,最终看点1是否有被访问过就行了。
但是不知道为什么交c++一直TLE,交g++就能过。

#include<cstdio> 
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<ctime> 

using namespace std;

#define outtime() cerr<<"User Time = "<<(double)clock()/CLOCKS_PER_SEC<<endl
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define bug printf("bug**")
#define coutlf(x) cout << fixed << setprecision(x)
#define uncoutlf  cout.unsetf(ios::fixed)
#define S_IT set<Node>::iterator
#define endl "\n"
#define fi first
#define se second
#define mp(a,b) make_pair(a,b)

int gcd(int a,int b) { return b?gcd(b,a%b):a;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
const double eps = 1e-7;
const ll mod = 998244353;
const int maxn = 2e3 + 7;

template<class T> inline void read(T &x){
    int f=0;x=0;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
    for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
    if(f)x=-x;
}

int n;
int vis[maxn];

struct Point{
    ll x, y;
}p[maxn];

struct QP{
    int a, b;
    ll d;
    bool operator < (const QP &t)const {
        return d > t.d;
    }
}qp[maxn * maxn];

ll get_dis(int a, int b) {
    ll x1 = p[a].x, y1 = p[a].y, x2 = p[b].x, y2 = p[b].y;
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
} 

void solve() {
    read(n);
    int S, cnt = 0;
    ll d = 0;
    for (int i = 1; i <= n; ++i) scanf("%lld %lld", &p[i].x, &p[i].y);
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            ll tmp = get_dis(i, j);
            qp[cnt++] = {i, j, get_dis(i, j)};
            qp[cnt++] = {j, i, get_dis(i, j)};
        }
    }
    sort(qp, qp + cnt);
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < cnt; ++i) {
        if (!vis[qp[i].a] && !vis[qp[i].b]) vis[qp[i].a] = vis[qp[i].b] = 1;
    }
    if (vis[1]) puts("YES");
    else puts("NO");
}

int _T;

int main() {
    read(_T);
    while (_T--) solve();
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值