幸运男孩--点的hash

 

幸运男孩
Time Limit: 1000 MSMemory Limit: 65536 K
Total Submit: 83(16 users)Total Accepted: 26(14 users)Rating: Special Judge: No
Description
 最近,Lur挺幸运的。并且因为他曾经创作了—幸运男孩 电脑游戏而成为学校最聪明的男生。这个游戏适合于两个人玩家 (假设分别称呼为 a,b) 在一个二维的平面上玩。在这个游戏中,平面上有n个不同的点。每次一个人可以从这个平面上去掉一个或者是在同一条直线上的任意多个点。第一个一次去掉多于二个点的选手赢得这场游戏。否则的话能够去掉平面上最后一个点的选手也可以赢得这场游戏。你可以假定这两个玩家都是足够聪明的,并且他们的每一个决定都是当前最优的。赢得这场游戏的选手将被授予“幸运男孩”的称号。
  给定n个点,你能告诉我谁将成为幸运男孩吗?注意,选手a总是首先开始游戏的。
Input
每组测试样例的第一行是一个整数n(0 < n <= 1000),后面的n行每行包含两个整数 x,y(0 <= x,y <= 10^8),描述平面上的每个点,输入直到文件末尾。
Output
如果a赢了,输出"a is the lucky boy.",否则的话,输出"b is the lucky boy."。每组测试数据的输出占一行。
Sample Input
3
0 0
1 1
2 2
3
0 0
1 1
2 3
Sample Output
a is the lucky boy.
b is the lucky boy.

代码:

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<map>
 4 #include<string.h>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 const int maxn=1005;
 9 
10 typedef pair<int,int> PII;
11 
12 PII pt[maxn];
13 
14 int gcd(int a,int b)
15 {
16     while(b!=0)
17     {
18         int c=a%b;
19         a=b;
20         b=c;
21     }
22     return a;
23 }
24 
25 PII get_vec(int i,int j)
26 {
27     int x=abs(pt[j].first-pt[i].first);
28     int y=abs(pt[j].second-pt[i].second);
29     if(x==0)
30     return make_pair(0,1);
31     if(y==0)
32     return make_pair(0,1);
33     int g=gcd(x,y);
34     return make_pair(x/g,y/g);
35 }
36 
37 int main()
38 {
39     int n;
40     //freopen("aa.txt","r",stdin);
41     while(scanf("%d",&n)!=EOF)
42     {
43         for(int i=0;i<n;i++)
44             scanf("%d %d",&pt[i].first,&pt[i].second);
45         if(n%3!=0)
46         {
47             printf("a is the lucky boy.\n");
48             continue;
49         }
50         sort(pt,pt+n);
51         bool ans=false;
52         for(int i=0;i<n;i++)
53         {
54             map<PII,bool>mp;
55             for(int j=i+1;j<n;j++)
56             {
57                 PII v=get_vec(i,j);
58                 if(mp[v])
59                 {
60                     ans=true;
61                     break;
62                 }
63                 else
64                 mp[v]=true;
65             }
66             if(ans)
67             break;
68         }
69         if(ans)
70         printf("a is the lucky boy.\n");
71         else
72         printf("b is the lucky boy.\n");
73     }
74     return 0;
75 }
View Code

 

转载于:https://www.cnblogs.com/zhanzhao/p/3608734.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值