zoukankan      html  css  js  c++  java
  • codeforces 183B

    /*
    题意:给出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;
    }

  • 相关阅读:
    [原创]如何在Windows下安装Bugfree2.0.0.1
    [原创]网站性能优化利器之一"google page speed"
    [原创]下一代Web 应用程序安全性测试工具HP WebInspect简介
    [原创]微软软件项目管理Team Foundation Server之测试人员
    [原创]Yeepay网站安全测试漏洞之跨站脚本注入
    [原创]软件测试过程改进的内容和注意事项
    [原创]快钱99bill网站安全性测试漏洞之“跨站式脚本注入”
    马化腾内部讲座:让产品自己召唤人
    [转贴]可用性测试
    [原创]浅谈缺陷分析的意义和方法
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/7257220.html
Copyright © 2011-2022 走看看