标签:
题目链接 http://acm.hust.edu.cn/vjudge/problem/21356
解题思路
枚举点对,相同的点对不必再判断一次。
代码
#include<stdio.h> #include<math.h> #include<algorithm> //#define LOCAL using namespace std; #define MAX_LEN 710 typedef struct point { double x, y; }Point; Point setP[MAX_LEN]; double xielv[MAX_LEN]; int maxp; void Solve(int n) { for(int i=0; i<n; i++) { int spe=1; int pos=0; for(int j=i+1; j<n; j++) { if(fabs(setP[j].x-setP[i].x)<1e-7) spe++; else xielv[pos++] = (setP[i].y-setP[j].y)/(setP[i].x-setP[j].x); } sort(xielv, xielv+pos); int x=2; int maxpo = spe; xielv[pos]=3.14159; //随便写的 for(int k=0; k<pos; k++) if(fabs(xielv[k]-xielv[k+1])<1e-7) x++; else { if(x>maxpo) maxpo=x; x=2; } if(maxpo>maxp) maxp = maxpo; } printf("%d\n", maxp); } int main() { #ifdef LOCAL freopen("data.txt", "r", stdin); freopen("ans.txt", "w", stdout); #endif int n; scanf("%d", &n); getchar(); getchar(); while(n--) { int ch = 0; int p = 0; ch=getchar(); while(ch != ‘\n‘ && ch!=EOF) { int x, y; ungetc(ch, stdin); scanf("%d%d", &x, &y); setP[p].x = x; setP[p].y = y; p++; getchar(); ch = getchar(); } maxp = 0; Solve(p); if(n) printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ZengWangli/p/5778610.html