uva 10881

这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变;

另外,又可以把蚂蚁看成运动方向不变;

代码:

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 #define maxn 10005
 5 
 6 char dir[][10]={"L","Turning","R"};
 7 
 8 int order[maxn];
 9 
10 struct ant
11 {
12     int id,p,d;
13     bool operator<(const ant &t)const
14     {
15         return p<t.p;
16     }
17 }st[maxn],now[maxn];
18 
19 int main()
20 {
21     int t,n,ti,l,ca=1,p,d;
22     char c;
23     scanf("%d",&t);
24     while(t--)
25     {
26         printf("Case #%d:
",ca++);
27         scanf("%d%d%d",&l,&ti,&n);
28         for(int i=0;i<n;i++)
29         {
30             scanf("%d %c",&p,&c);
31             d=(c=='L'?-1:1);
32             st[i]=(ant){i,p,d};
33             now[i]=(ant){0,p+ti*d,d};
34         }
35         sort(st,st+n);
36         for(int i=0;i<n;i++)
37             order[st[i].id]=i;
38         sort(now,now+n);
39         for(int i=0;i<n-1;i++)
40             if(now[i].p==now[i+1].p)
41                 now[i].d=now[i+1].d=0;
42         for(int i=0;i<n;i++)
43         {
44             int a=order[i];
45             if(now[a].p<0||now[a].p>l)puts("Fell off");
46             else printf("%d %s
",now[a].p,dir[now[a].d+1]);
47         }
48         printf("
");
49     }
50     return 0;
51 }
View Code
原文地址:https://www.cnblogs.com/yours1103/p/3388784.html