codeforces 183B - Zoo

/*
题意:给出n,m。

n表示给出的n个横坐标为1-n,y为0的坐标m表示以下有m个坐标,在横坐标上的点
向各个角度看,在可以看到最多的点在同一条直线上的点的做多值为横坐标这一点的值,最后各个
横坐标的值的和为多少
思路:由于m的值为枚举随意的两个点连成的直线,看在直线上的点有多少,看这条线和横坐标的值为
多少。是否是整值点。假设是就记录这个整值点的最大值
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 +5;
const double eps =1e-3;
int b[maxn];
struct Point
{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y) {}
};
typedef Point Vector;
Vector operator - (Point A,Point B)
{
    return Vector(A.x-B.x,A.y-B.y);
}
Vector operator +(Vector A,Vector B)
{
    return Vector(A.x+B.x,A.y+B.y);
}
Vector operator * (Vector A,double p)
{
    return Vector(A.x*p,A.y*p);
}
double Cross(Vector A,Vector B)
{
    return A.x*B.y-A.y*B.x;
}
int dcmp(double x)
{
    if(fabs(x)<eps)  return 0;
    return x>eps?

1:-1;
}
struct Line
{
    Point p;
    Vector v;
};
int GetLineIntersection(Line L1,Line L2)
{
    if(dcmp(Cross(L1.v,L2.v))==0)
        return 0;
    Vector u=L1.p-L2.p;
    int t=Cross(L2.v,u)/Cross(L1.v,L2.v);
    Point answer;
    answer=L1.p+L1.v*t;
    int temp=(int)(answer.x+0.5);
    if(dcmp(answer.x)>0&&dcmp(answer.x-temp)==0&&dcmp(answer.y)==0&&temp<=1000000)
        return temp;
    return 0;
}
int main()
{
    int n,m;
    Point a[300];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(b,0,sizeof(b));
        for(int i=0; i<m; i++)
            scanf("%lf%lf",&a[i].x,&a[i].y);
        Line ox;
        ox.p.x=0;
        ox.p.y=0;
        ox.v.x=1;
        ox.v.y=0;
        Line l1;
        for(int i=0; i<m; i++)
        {
            for(int j=i+1; j<m; j++)
            {
                int have=2;
                for(int k=j+1; k<m; k++)
                {
                    if(dcmp(Cross(a[i]-a[j],a[k]-a[j]))==0)
                        have++;
                }
                l1.p=a[i];
                l1.v=a[i]-a[j];
                int flag=GetLineIntersection(ox,l1);
                if(flag)
                {
                    a[299].x=flag;
                    a[299].y=0;
                    if(dcmp(Cross(a[i]-a[j],a[299]-a[j]))==0)
                    b[flag]=max(b[flag],have);
                }
            }
        }
        int sum=0;
        for(int i=1; i<=n; i++)
            if(b[i])
                sum+=b[i];
            else
                sum++;
        cout << sum << endl;
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值