求平面上在一条直线上的点的个数

本文介绍了一款名为LuckyBoy的游戏,该游戏由两名玩家在二维平面上进行。文章详细解释了游戏规则,并通过示例输入输出展示了如何确定哪位玩家会成为LuckyBoy。此外,还提供了两段C++代码实现,用于自动判断游戏结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这样的题差不多有点类似,都是先按平面上的斜率排序,O(n*n)

Lucky Boy

TimeLimit: 1 Second   MemoryLimit: 32 Megabyte

Totalsubmit: 1   Accepted: 1  

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.

Source

2011 Heilongjiang collegiate programming contest

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>

using namespace std;

int a[1010],b[1010];
struct node
{
    double k,b;    
}s[500000];
int cmp(node x,node y)
{
    if(x.k!=y.k)return x.k<y.k;
    return  x.b<y.b;     
}
int main()
{
    int i,j,k,l;
    int n;
   while(scanf("%d",&n)==1)
   {
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i],&b[i]);        
        }  
        double k1,m;    
        int y1,y2,x1,x2; 
        int ans=0;
        for(i=1;i<n;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                x1=a[i];y1=b[i];
                x2=a[j];y2=b[j];
                if(x2==x1) 
                {
                    k1=1<<30;
                    m=x1;    
                }              
               else 
               { 
                    k1=(y2-y1)*1.0/(x2-x1);
                    m=y1-k1*x1;
                }
                s[ans].k=k1;
                s[ans++].b=m;
            }    
        }
        sort(s,s+ans,cmp);
        int mmax=1;
        for(i=1;i<ans;i++)
        {
            int temp=1;
            while(i<ans&&fabs(s[i].b-s[i-1].b)<1e-9&&fabs(s[i].k-s[i-1].k)<1e-9)
            {
                i++;
                temp++;                
            } 
            mmax=max(mmax,temp);
            if(mmax>=3) break;
        }
        if(mmax>=3) puts("a is the lucky boy.");
        else
        {
             if(n%3!=0)    puts("a is the lucky boy.");
             else puts("b is the lucky boy.");
        }
    }
    return 0;
}

http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=8252#problem/G

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#define Maxinf 2147483647
using namespace std;
int a[1000],b[1000];
struct node
{
    double k,b;    
}s[500000];
int cmp(node x,node y)
{
    if(x.k!=y.k)return x.k<y.k;
    return  x.b<y.b;     
}
int main()
{
    int t;
    //double temp=1e-9;
    //printf("%lf",temp);
    scanf("%d",&t);
    int i,j,k,l;
    for(l=1;l<=t;l++)
    {
        int n;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i],&b[i]);        
        }  
        //printf("dfdfd");
        if(n<=2) {printf("Case %d: ",l);printf("%d\n",n);continue;}
        // printf("dfdfd");
        double k1,m;    
        int y1,y2,x1,x2; 
        int ans=0;
        
        //cout<<endl;
        
        for(i=1;i<n;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                x1=a[i];y1=b[i];
                x2=a[j];y2=b[j];
               // cout<<x1-x2<<endl;
                if(x2==x1) 
                {
                    k1=x1;
                    m=1<<30;    
                }              
               else 
               { 
                    k1=(y2-y1)*1.0/(x2-x1);
                    m=y1-k1*x1;
                }
                s[ans].k=k1;
                s[ans++].b=m;
            }    
        }
        sort(s,s+ans,cmp);
        //for(i=0;i<ans;i++) printf("%lf %lf\n",s[i].k,s[i].b);
        int mmax=1;
        for(i=1;i<ans;i++)
        {
            int temp=1;
            while(i<ans&&fabs(s[i].b-s[i-1].b)<1e-9&&fabs(s[i].k-s[i-1].k)<1e-9)
            {
                i++;
                temp++;                
            } 
            mmax=max(mmax,temp);
        }
        for(i=2;i<=700;i++) if(i*(i-1)/2==mmax) break;
        //if(i==701) while(1);
        printf("Case %d: ",l);
        printf("%d\n",i);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值