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;
}





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值