对于每一个已经开始运动的轮子要求它周围和他相接触的轮子的运动状态,然后让那些轮子依次进入队列= =
速度关系== 高中学过物理应该都知道吧
1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 #include<algorithm> 5 #include<iostream> 6 #include<queue> 7 using namespace std; 8 #define maxn 2000 9 struct node 10 { 11 int x,y,r,rate1,rate2; 12 int flag; 13 }; 14 int hash[maxn]; 15 node a[maxn]; 16 queue<node>q; 17 int dis(node a,node b) 18 { 19 int f=0; 20 double len=pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0); 21 if(len-pow(a.r+b.r,2.0)<=0.00000001) 22 f=1; 23 return f; 24 } 25 int gcd(int x,int y) 26 { 27 int ans; 28 if(y!=0) 29 ans=gcd(y,x%y); 30 else 31 ans=x; 32 return ans; 33 } 34 int main() 35 { 36 int t,n; 37 scanf("%d",&t); 38 while(t--) 39 { 40 while(!q.empty()) 41 q.pop(); 42 memset(hash,0,sizeof(hash)); 43 scanf("%d",&n); 44 for(int i=0;i<n;i++) 45 { 46 scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].r); 47 a[i].flag=0; 48 } 49 a[0].flag=1; 50 a[0].rate1=1; 51 a[0].rate2=1; 52 q.push(a[0]); 53 while(!q.empty()) 54 { 55 node now=q.front(); 56 q.pop(); 57 for(int i=1;i<n;i++) 58 { 59 if(hash[i]) 60 continue; 61 node b; 62 if(dis(a[i],now)&&hash[i]==0) 63 { 64 if(now.flag==1) 65 a[i].flag=-1; 66 else if(now.flag==-1) 67 a[i].flag=1; 68 b.x=a[i].x; 69 b.y=a[i].y; 70 b.r=a[i].r; 71 hash[i]=1; 72 a[i].rate1=now.rate1*now.r; 73 a[i].rate2=now.rate2*a[i].r; 74 int cnt=gcd(a[i].rate1,a[i].rate2); 75 a[i].rate1/=cnt; 76 a[i].rate2/=cnt; 77 q.push(a[i]); 78 } 79 } 80 } 81 for(int i=0;i<n;i++) 82 { 83 if(a[i].flag==0) 84 { 85 printf("not moving\n"); 86 } 87 else if(a[i].flag==1) 88 { 89 if(a[i].rate2==1) 90 printf("%d clockwise\n",a[i].rate1); 91 else 92 printf("%d/%d clockwise\n",a[i].rate1,a[i].rate2); 93 } 94 else 95 { 96 if(a[i].rate2==1) 97 printf("%d counterclockwise\n",a[i].rate1); 98 else 99 printf("%d/%d counterclockwise\n",a[i].rate1,a[i].rate2); 100 } 101 } 102 } 103 return 0; 104 }