题目链接: http://poj.org/problem?id=1118
题意: 给定n个点, 求在同一直线上的点最多的直线上点的数目.
解法: 简单题目, 规模比较小, 暴力搜索.
#include <iostream> using namespace std; #define MAXN 700 struct Point{ int x,y; }p[MAXN]; int main(){ int N; cin>>N; while(N){ int i,j,k; for(i=0;i<N;++i){ cin>>p[i].x>>p[i].y; } int max = 0; for(i=0;i<N;++i){ for(j=i+1;j<N;++j){ int s = 2; for(k=j+1;k<N;++k){ int t1 = (p[i].x - p[j].x)*(p[j].y - p[k].y); int t2 = (p[i].y - p[j].y)*(p[j].x - p[k].x); if(t1 == t2) s++; } if(s>max) max = s; } } cout<<max<<endl; cin>>N; } return 0; }