1. 程式人生 > >codeforces 183B - Zoo

codeforces 183B - Zoo

struct temp main div type include per def typedef

/*
題意:給出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;
}

codeforces 183B - Zoo