标签:des style blog http color java os io strong
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3457 Accepted Submission(s): 1290
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 7 const double eps=1e-8; 8 const int maxn=1005; 9 int f[maxn]; 10 struct Point 11 { 12 double x,y; 13 Point(){} 14 Point(double x,double y):x(x),y(y){} 15 }; 16 struct Line 17 { 18 Point a,b; 19 }L[maxn]; 20 typedef Point Vector; 21 Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);} 22 int dcmp(double x) 23 { 24 if(fabs(x)<eps) return 0; 25 else return x<0?-1:1; 26 } 27 double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积 28 29 bool judge(Line a,Line b)//Cross(v,w)=0时w在v上,>0时w在v上方,<0时w在v下方 30 { 31 if(dcmp(Cross(a.a-b.a,b.b-b.a)*Cross(a.b-b.a,b.b-b.a))<=0 32 &&dcmp(Cross(b.a-a.a,a.b-a.a)*Cross(b.b-a.a,a.b-a.a))<=0) 33 return true; 34 return false; 35 } 36 int findset(int x){return f[x]!=x?f[x]=findset(f[x]):x;} 37 void Union(int a,int b) 38 { 39 a=findset(a);b=findset(b); 40 if(a!=b) f[a]=b; 41 } 42 int main() 43 { 44 int t,n,i,j,id; 45 char op[5]; 46 double x1,y1,x2,y2; 47 scanf("%d",&t); 48 while(t--) 49 { 50 scanf("%d",&n); 51 int cnt=0; 52 for(i=0;i<n;i++) 53 { 54 scanf("%s",op); 55 if(op[0]==‘P‘) 56 { 57 scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); 58 L[++cnt].a=Point(x1,y1);L[cnt].b=Point(x2,y2); 59 f[cnt]=cnt; 60 for(j=1;j<=cnt-1;j++) 61 if(judge(L[cnt],L[j])) 62 Union(j,cnt); 63 } 64 else 65 { 66 int ans=0;scanf("%d",&id); 67 id=findset(id); 68 for(j=1;j<=cnt;j++) 69 if(findset(j)==id) 70 ans++; 71 printf("%d\n",ans); 72 } 73 } 74 if(t) printf("\n"); 75 } 76 return 0; 77 }
标签:des style blog http color java os io strong
原文地址:http://www.cnblogs.com/xiong-/p/3930427.html