标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1274 Accepted Submission(s): 366
题解:错了好一会儿,发现是排序那里写错了,多此一举。。。都怪以前的qsort,使我现在都快不敢直接判断了。。。
思路是先找出所有点,求出相同直线的个数sum,根据n*(n - 1)/2=sum,求出n;借助队友的思路;
ac代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; typedef long long LL; int tp; struct Point{ double x, y; Point(){ } Point(double x, double y){ this->x = x; this->y = y; } }; Point point[1010]; struct Node{ double k, b; Node(double k,double b){ this->k = k; this->b = b; } Node(){ } bool operator < (const Node &a) const{ if(k != a.k){//直接比就可以。。。 return k < a.k; } else// return b < a.b; } }; Node dt[250000]; Node operator + (Point a,Point b){ double k, t; k = (a.y - b.y) / (a.x - b.x); t = a.y - k * a.x; return Node(k,t); } bool operator == (Node a, Node b){ if(abs(a.k - b.k) < 1e-6){ if(abs(a.b - b.b) < 1e-6){ return true; } } return false; } int getn(int a, int b, int c){ double t = b * b - 4 * a * c; double x = ( -b + sqrt(t) ) / (2.0 * a); return (int)x; } int main(){ int N; while(~scanf("%d",&N)){ double x, y; tp = 0; for(int i = 0; i < N; i++){ scanf("%lf%lf",&x,&y); point[i] = Point(x, y); for(int j = 0; j < i; j++){ dt[tp++] = point[i] + point[j]; } } if(N == 1){ puts("1");continue; } sort(dt, dt + tp); int ans = 0, temp = 0; for(int i = 1; i < tp; i++){ if(dt[i] == dt[i - 1]){ temp++; ans = max(ans,temp); } else temp = 0; } ans++; printf("%d\n", getn(1, -1, -2 * ans) ); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5356131.html