UVALive 4807||SYSU 2379 Cocircular Points 几何

题意:问最多多少个点可以在一个圆的边上。

思路:三点确定一个园,枚举。

可惜在scu上TLE了。。。。。。。。。。。。。。。。其他oj可以A

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define eps 1e-6
using namespace std;
int n;
double x[105],y[105];
int ans;
void linecross(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4,double &x5,double &y5)//已知四个点求直线相交的点的坐标
//(这种求法包括了直线斜率不存在或为0的情况下)
{
    double A1 = y2 - y1;
    double B1 = x1 - x2;
    double C1 = y1 * (-B1) - x1 * A1;
    double A2 = y4 - y3;
    double B2 = x3 - x4;
    double C2 = y3 *(-B2) - x3 * A2;
    x5 = (C2 * B1 - C1 * B2) / (A1 * B2 - A2 * B1);
    y5 = (C2 * A1 - C1 * A2) / (B1 * A2 - B2 * A1);
}
int coun(int a,int b,int c)
{
    if((y[b]-y[a])*(x[c]-x[a])==(y[c]-y[a])*(x[c]-x[a]))return 2;
    double x1,x2,x3,x4,x5,y1,y2,y3,y4,y5;
    x1=(x[a]+x[b])/2;
    y1=(y[a]+y[b])/2;
    x3=(x[a]+x[c])/2;
    y3=(y[a]+y[c])/2;
    if(x[a]==x[b])
    {
        x2=x1-1;
        y2=y1;
    }
    else
    {
        x2=x1+(y[a]-y[b]);
        y2=y1-(x[a]-x[b]);
    }
    if(x[a]==x[c])
    {
        x4=x3-1;
        y4=y3;
    }
    else
    {
        x4=x3+(y[a] - y[c]);
        y4=y3-(x[a]-x[c]);
    }
    linecross(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5);
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        //if(i==a||i==b||i==c)continue;
        if(abs((x[i]-x5)*(x[i]-x5)+(y[i]-y5)*(y[i]-y5)-(x[a]-x5)*(x[a]-x5)-(y[a]-y5)*(y[a]-y5))<eps)cnt++;
    }
    return cnt;
}
int main()
{
    while(scanf("%d",&n)&&n)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%lf%lf",&x[i],&y[i]);
        }
        if(n==1)ans=1;
        else ans=2;
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                for(int k=j+1;k<=n;k++)
                {
                    ans=max(ans,coun(i,j,k));
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


你可能感兴趣的:(Baoge)