标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 152 Accepted Submission(s): 87
1 #include"stdio.h" 2 #include"string.h" 3 #include"stdlib.h" 4 #include"algorithm" 5 #include"queue" 6 #include"math.h" 7 #include"iostream" 8 #include"vector" 9 #define M 100009 10 #define inf 0x3f3f3f3f 11 #define eps 1e-9 12 #define PI acos(-1.0) 13 #include"map" 14 #include"vector" 15 #include"set" 16 #include"string" 17 #include"stack" 18 #define LL __int64 19 using namespace std; 20 struct node 21 { 22 int x,y; 23 node(){} 24 node(int x,int y) 25 { 26 this->x=x; 27 this->y=y; 28 } 29 }; 30 struct line 31 { 32 node s,e; 33 }col[M],row[M]; 34 int cmp(line a,line b) 35 { 36 return a.s.x<b.s.x; 37 } 38 int ok(line a,line b,line c) 39 { 40 if(c.s.x<=a.s.x 41 &&c.e.x>=b.s.x 42 &&c.s.y<=min(a.s.y,b.s.y) 43 &&c.s.y>=max(a.e.y,b.e.y)) 44 return 1; 45 return 0; 46 } 47 int main() 48 { 49 int T,kk=1; 50 cin>>T; 51 while(T--) 52 { 53 int n; 54 scanf("%d",&n); 55 int x1,x2,y1,y2; 56 int col_k=0; 57 int row_k=0; 58 for(int i=1;i<=n;i++) 59 { 60 scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 61 if(x1==x2) 62 { 63 ++col_k; 64 col[col_k].s=node(x1,max(y1,y2)); 65 col[col_k].e=node(x1,min(y1,y2)); 66 } 67 else if(y1==y2) 68 { 69 ++row_k; 70 row[row_k].s=node(min(x1,x2),y1); 71 row[row_k].e=node(max(x1,x2),y1); 72 } 73 } 74 sort(col+1,col+col_k+1,cmp); 75 int sum=0; 76 for(int i=1;i<=col_k;i++) 77 { 78 for(int j=i+1;j<=col_k;j++) 79 { 80 int s=0; 81 for(int k=1;k<=row_k;k++) 82 { 83 if(ok(col[i],col[j],row[k])) 84 s++; 85 } 86 s--; 87 if(s>=1) 88 { 89 s=s*(s+1)/2; 90 sum+=s; 91 } 92 } 93 } 94 printf("Case #%d:\n",kk++); 95 printf("%d\n",sum); 96 } 97 return 0; 98 } 99 /* 100 23 101 6 102 1 0 1 5 103 5 0 5 5 104 0 4 6 4 105 0 2 6 2 106 0 1 6 1 107 3 0 3 3 108 109 2 110 0 0 0 5 111 6 0 6 6 112 113 7 114 0 1 100 1 115 0 3 100 3 116 0 95 100 95 117 0 97 100 97 118 3 0 3 10 119 3 90 3 100 120 90 0 90 110 121 122 10 123 0 1 100 1 124 0 2 100 2 125 0 3 100 3 126 0 4 100 4 127 0 5 100 5 128 10 0 10 110 129 11 0 11 110 130 12 0 12 110 131 13 0 13 110 132 15 0 15 110 133 134 */
标签:
原文地址:http://www.cnblogs.com/mypsq/p/4711949.html