Uva10881 Piotr's Ants

蚂蚁相撞会各自回头。←可以等效成对穿而过,这样移动距离就很好算了。

末状态蚂蚁的顺序和初状态其实是相同的。

那么剩下的就是记录每只蚂蚁的标号,模拟即可。

 1 /*by SilverN*/
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<vector>
 8 using namespace std;
 9 const int mxn=10010;
10 struct ants{
11     int id,p,dir;
12     int pos;
13 }a[mxn];
14 int cmp(const ants x,const ants y){
15     return x.p<y.p;
16 }
17 int cmp2(const ants x,const ants y){
18     return x.pos<y.pos;
19 }
20 int l,t,n;
21 int mp[mxn];
22 int main(){
23     int T,i,j;
24     scanf("%d",&T);
25     int cas=0;
26     while(T--){
27         printf("Case #%d:\n",++cas);
28         scanf("%d%d%d",&l,&t,&n);
29         char dr;
30         for(i=1;i<=n;i++){
31             scanf("%d %c",&a[i].p,&dr);
32             if(dr=='L') a[i].dir=-1;
33             else a[i].dir=1;
34         }
35         for(i=1;i<=n;i++){
36             a[i].id=i;
37             a[i].pos=a[i].p+t*a[i].dir;
38         }
39         sort(a+1,a+n+1,cmp);
40         for(i=1;i<=n;i++){
41             mp[a[i].id]=i;
42         }
43         sort(a+1,a+n+1,cmp2);
44         for(i=1;i<n;i++){
45             if(a[i].pos==a[i+1].pos){
46                 a[i].dir=a[i+1].dir=0;
47             }
48         }
49         for(i=1;i<=n;i++){
50             int thi=mp[i];
51             if(a[thi].pos<0 || a[thi].pos>l){
52                 printf("Fell off\n");continue;
53             }
54             printf("%d ",a[thi].pos);
55             if(a[thi].dir==-1)printf("L\n");
56             else if(a[thi].dir==1)printf("R\n");
57             else printf("Turning\n");
58         }
59         printf("\n");
60     }
61     return 0;
62 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/6089740.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值