zoukankan      html  css  js  c++  java
  • 幸运男孩--点的hash

    幸运男孩
    Time Limit: 1000 MS Memory 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.
    ");
    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.
    ");
    71         else
    72         printf("b is the lucky boy.
    ");
    73     }
    74     return 0;
    75 }
    View Code
  • 相关阅读:
    论文翻译:2020_DARCN_A Recursive Network with Dynamic Attention for Monaural Speech Enhancement
    论文翻译:2020_demucs_Real Time Speech Enhancement in the Waveform Domain
    论文翻译:2021_A Perceptually Motivated Approach for Lowcomplexity, Realtime Enhancement of Fullband Speech
    tomcat架构分析及配置详解
    深入了解SpringMVC源码解析
    Spring MVC高级应用
    Nginx应用场景配置
    SpringSecurity基础场景应用大全
    SpringBoot基础应用
    Spring MVC应用
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3608734.html
Copyright © 2011-2022 走看看