标签:
Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1838 Accepted Submission(s): 552
1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 using namespace std; 5 6 #define eps 1e-8 7 #define pi acos(-1.0) 8 #define N 750 9 10 int n; 11 12 struct point 13 { 14 double x, y; 15 point(){} 16 point(double _x, double _y ):x(_x), y(_y){} 17 }; 18 19 point P[N]; 20 double ang[2*N]; 21 int main() 22 { 23 //printf("%d", 700*699*698/6); 24 int T, n; 25 scanf("%d", &T); 26 while(T--) 27 { 28 scanf("%d", &n); 29 for(int i = 0; i < n; i++) 30 scanf("%lf %lf", &P[i].x, &P[i].y); 31 32 long long ans = (long long)n*(n-1)*(n-2)*(n-3)/24;//C(n,4) 33 for(int i = 0; i < n; i++) 34 { 35 long long cnt = (long long)(n-1)*(n-2)*(n-3)/6;//cnt记录包含i的三角形个数 36 37 int c = 0; 38 for(int j = 0; j < n; j++) 39 { 40 if(i == j) continue; 41 ang[c++] = atan2(P[j].y-P[i].y, P[j].x - P[i].x); 42 } 43 44 sort(ang, ang+c); 45 for(int j = c; j < 2*c; j++) 46 { 47 ang[j] = ang[j-c] + 2*pi; 48 // printf("a-- %lf\n", ang[j-c] * 180.0 /pi); 49 } 50 // puts(""); 51 52 int k = 1; 53 54 //puts("haha");while(t < 1000000000) t++; 55 for(int j = 0; j < c; j++)//不包含i的三角形 56 { 57 while(ang[k] - ang[j] < pi) k++; 58 int d = k-j-1; 59 // printf("d = %d\n", d); 60 if(d > 1) cnt -= d*(d-1)/2; 61 } 62 63 ans -= cnt; 64 } 65 printf("%I64d\n",ans); 66 } 67 return 0; 68 }
标签:
原文地址:http://www.cnblogs.com/shanyr/p/4688580.html