Wheels(bfs遍历,CERC 2014)
2015-12-31 08:41
260 查看
原题链接:http://acm.hnu.cn/online/?action=problem&type=show&id=13397
对于每一个已经开始运动的轮子要求它周围和他相接触的轮子的运动状态,然后让那些轮子依次进入队列= =
速度关系== 高中学过物理应该都知道吧
对于每一个已经开始运动的轮子要求它周围和他相接触的轮子的运动状态,然后让那些轮子依次进入队列= =
速度关系== 高中学过物理应该都知道吧
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 }
相关文章推荐
- Sum(构造,枚举)
- 1278 相离的圆(51nod)
- 1279 扔盘子(51nod)
- Concert Tour(Uvalive 6853)
- 二维hash(Uva 12886)
- 优先队列实现哈弗曼最小权值
- C#实现自动升级(附源码)
- 背包问题------ 分类: ACM 2015-08-03 20:57 1人阅读 评论(0
- Cent Savings (DP) 分类: ACM dp 2015-08-0
- Judging Troubles (multiset查找) 分类: ACM STL
- Judging Troubles (multiset查找) 分类: ACM STL
- Joke with permutation 分类: ACM 2015-08-03 14:09 1
- HNU Knockout Racing 分类: ACM 2015-08-03 13:35 1人
- Crazy Search(POJ1200) 分类: poj 2015-07-25 10:15 6
- Delicious Apples(多校联合训练) 分类: ACM 多校 201
- 1080 两个数的平方和 分类: 51nod 2015-07-20 22:20 11人阅读
- 1066 Bash游戏 分类: 51nod 2015-07-20 22:15 5人阅读 评
- 1088 最长回文子串 分类: 51nod 2015-07-20 22:09 8人阅读 评
- 1083 矩阵取数问题 分类: 51nod 2015-07-20 22:05 9人阅读 评
- 1083 矩阵取数问题 分类: 51nod 2015-07-20 22:05 9人阅读 评