Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4381 Accepted Submission(s): 1015c++
1 # include <bits/stdc++.h> 2 using namespace std; 3 const int N = 20; 4 const int Max = 1001; 5 int vis[222][222]; 6 7 struct point 8 { 9 int x, y; 10 11 int input() 12 { 13 scanf("%d%d", &x, &y); 14 if(vis[x + 100][y + 100]) 15 return 0; 16 vis[x + 100][100 + y] = 1; 17 return 1; 18 } 19 }p[N]; 20 21 int dis2(point a, point b) 22 { 23 return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); 24 } 25 struct triangle 26 { 27 int num[3]; 28 void get_num(point a,point b,point c) 29 { 30 num[0] = dis2(a,b); 31 num[1] = dis2(a,c); 32 num[2] = dis2(b,c); 33 sort(num, num + 3); 34 } 35 }tri[Max]; 36 // 判斷類似 37 bool Issimi(triangle s1, triangle s2) 38 { 39 return (s1.num[0] * s2.num[1] == s1.num[1] * s2.num[0])&& 40 (s1.num[0] * s2.num[2] == s1.num[2] * s2.num[0])&& 41 (s1.num[1] * s2.num[2] == s1.num[2] * s2.num[1]); 42 } 43 // 判斷直線 44 bool Isline(point a, point b, point c) 45 { 46 int x1 = b.x - a.x, y1 = b.y - a.y, 47 x2 = c.x - a.x, y2 = c.y - a.y; 48 return x1 * y2 != x2 * y1; 49 } 50 int main() 51 { 52 int n; 53 int vis1[Max]; 54 while(scanf("%d",&n) != EOF) 55 { 56 if(!n) 57 break; 58 memset(vis, 0, sizeof(vis)); 59 memset(vis1, 0, sizeof(vis1)); 60 61 for(int i = 0; i < n; i++) 62 if(!p[i].input()) // 處理重複的點 63 i--, n--; 64 int st = 0; // 記錄三角形個數 65 for(int i = 0; i < n; i++) 66 { 67 for(int j = i + 1; j < n; j++) 68 { 69 for(int k = j + 1; k < n; k++) 70 { 71 if(Isline(p[i], p[j], p[k])) 72 tri[st++].get_num(p[i],p[j],p[k]); 73 } 74 } 75 } 76 77 int sum = 0, tep; 78 for(int i = 0; i < st; i++) 79 { 80 if(!vis1[i]) // 沒有訪問過 81 { 82 tep = 1; 83 vis1[i] = 1; 84 for(int j = i + 1; j < st; j++) 85 if(!vis1[j] && Issimi(tri[i], tri[j])) 86 { 87 tep++; 88 vis1[j] = 1; 89 } 90 if(tep > sum) 91 sum = tep; 92 } 93 } 94 printf("%d\n",sum); 95 } 96 return 0; 97 }