zoukankan      html  css  js  c++  java
  • NEFU 699 Lucky Boy 博弈?几何?

    Lucky Boy

    Time Limit 1000ms

    Memory Limit 65536K

    description

      Recently, Lur have a good luck. He is also the cleverest boy in his school as he create the most popular computer game – Lucky Boy. The game is played by two players, a and b, in 2d planar .In the game Lucky Boy, there are n different points on plane, each time one can remove one or multiple co-line points from the plane. The one who can firstly remove more than two points from the plane wins. The one who removes the last point on the plane can also win the game. You may assume that two players are both clever enough that they can always make the best choice. The winner is called Lucky Boy.
    Given the n points, can you tell me who will be the Lucky Boy ? Note that player a will always the first one to remove points from the plane.
    							

    input

      The first line of each case is an integer n(0< n <=10^3), following n lines each contains two integers x and y(0 <= x, y <= 10^8), describing the coordinates of each point. Ended by EOF.
    							

    output

     Output “a is the lucky boy.” in a single line if a win the game, otherwise you should output  “b is the lucky boy.” in a single line.
    							

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

    当有三点共线时一定是a获胜。

    所以博弈的情况下没有三点共线。所以a和b可以从棋盘上取走1个棋子或两个棋子。

    当棋盘上只有一个点时,直接取走获胜,1为必胜点。

    当两个点时,直接取走,必胜点。

    三个点时,取走1个棋子剩2个,取走2个棋子剩1个,只能到达必胜点,为必败点。

    4,必胜点。5,必胜点。6必败点。

    所以n%3==0时b胜,否则a胜。

    怎样求三点共线。。

    求出点i到其他所有点的斜率,排序,有相等的斜率说明有三点共线。

    -------------

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    
    const double OO=1e17;
    const double eps=0.0000001;
    
    struct POINT
    {
        int x;
        int y;
        int num;
    } a[1111];
    
    double f[1111][1111];
    
    bool cmp(POINT a,POINT b)
    {
        if (a.x==b.x)
        {
            return a.y<b.y;
        }
        return a.x<b.x;
    }
    
    int n,m;
    double last;
    int ss;
    bool ok;
    
    int main()
    {
        while (~scanf("%d",&n))
        {
            memset(a,0,sizeof(a));
            memset(f,0,sizeof(f));
            for (int i=0; i<n; i++)
            {
                scanf("%d%d",&a[i].x,&a[i].y);
            }
    
            for (int i=0; i<n; i++)
            {
                m=0;
                for (int j=0; j<n; j++)
                {
                    if (i==j) continue;
                    if (a[j].x-a[i].x==0)
                    {
                        f[i][m++]=OO;
                        continue;
                    }
                    f[i][m++]=(double)(a[j].y-a[i].y)/(double)(a[j].x-a[i].x);
                }
                sort(f[i],f[i]+m);
                last=-OO;
                ss=0;
                ok=true;
                for (int j=0; j<m; j++)
                {
                    if ( abs(f[i][j]-last)<eps )
                    {
                        ss++;
                    }
                    else
                    {
                        last=f[i][j];
                        ss=1;
                    }
                    if (ss>=2)
                    {
                        ok=false;
                        break;
                    }
                }
                if (!ok) break;
            }
            if (!ok)
            {
                puts("a is the lucky boy.");
            }
            else
            {
                if (n%3==0)
                {
                    puts("b is the lucky boy.");
                }
                else
                {
                    puts("a is the lucky boy.");
                }
            }
    
        }
        return 0;
    }
    





  • 相关阅读:
    为什么要有这个“修改”按钮
    用C++托管程序来保护敏感数据
    计算机辅助学习软件CAS和CAL的区别和联系
    C#/C++获取CPU和硬盘系列号的源代码
    计算机辅助学习英语单词分组的设计
    IC设计过程
    中国25位最具影响力的IC人物
    PLD/FPGA开发环境
    挑战功耗:低功耗ASIC设计技术
    沙子变黄金——CPU制造全过程
  • 原文地址:https://www.cnblogs.com/cyendra/p/3226384.html
Copyright © 2011-2022 走看看