CF某gym G
题目大意:给定n个点,求一条直线最多能经过几个点(n<=1000)
做法:大暴力。。。枚举每一个点作为直线的端点,然后求出剩下n-1个点和它的斜率,斜率相同的说明可以同时在一条直线上
#include<bits/stdc++.h> #define eps 1e-7 #define N 500005 using namespace std; int n,cnt;double tmp[N*10]; struct Node{int x,y;}p[N]; inline double getk(Node aa,Node bb){return 1.0*(aa.y-bb.y)/(double)(aa.x-bb.x);} int main(){ int cas=0; while (scanf("%d",&n)!=EOF){ if (n==0) return 0; cnt=0;cas++;int ans1=0; for (int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y); for (int i=1;i<n;i++){ cnt=0; for (int j=i+1;j<=n;j++){ if (p[i].x==p[j].x) tmp[++cnt]=1e9; else tmp[++cnt]=getk(p[i],p[j]); //printf("ID%d %d %.4lf\n",i,j,tmp[cnt]); } sort(tmp+1,tmp+cnt+1); int ans=0;tmp[0]=-1e9; for (int i=1;i<=cnt;i++){ if (fabs(tmp[i]-tmp[i-1])>eps){ans=1;ans1=max(ans1,ans);continue;} else ans++,ans1=max(ans1,ans); } }ans1++; if (ans1<4) ans1=0; printf("Photo %d: %d points eliminated\n",cas,ans1); } return 0; }