标签:
思路:模拟,看成对穿而过求终状态,然而相对顺序不变,排序即可。
1 #include <iostream>
2 #include<stdio.h>
3 #include<stdlib.h>
4 #include<string.h>
5 #include<algorithm>
6 #include<math.h>
7
8 using namespace std;
9
10 const char dirname[3][10]= {"L","Turning","R"};
11 int order[10010];
12
13 struct ant
14 {
15 int id,position,direct;
16 } before[10010],after[10010];
17
18 bool cmp(ant x,ant y)
19 {
20 return x.position<y.position;
21 }
22
23 int main()
24 {
25 int c,cnt;
26 scanf("%d",&c);
27 for(cnt=1; cnt<=c; cnt++)
28 {
29 int t,l,n,i,tmp;
30 printf("Case #%d:\n",cnt);
31 scanf("%d%d%d",&l,&t,&n);
32 for(i=0; i<n; i++)
33 {
34 int p,d;
35 char dir;
36 scanf("%d %c",&p,&dir); //#尼玛中间要空格呀!!!
37 d=(dir==‘L‘?-1:1); //#这样求终态较方便
38 before[i]=(ant)
39 {
40 i,p,d
41 };
42 after[i]=(ant)
43 {
44 0,p+d*t,d
45 };
46 }
47 sort(before,before+n,cmp);
48 for(i=0; i<n; i++)
49 order[before[i].id]=i;
50 sort(after,after+n,cmp);
51 for(i=0; i<n-1; i++)
52 if(after[i].position==after[i+1].position)
53 after[i].direct=after[i+1].direct=0;
54 for(i=0; i<n; i++)
55 {
56 tmp=order[i];
57 if(after[tmp].position<0||after[tmp].position>l) printf("Fell off\n");
58 else printf("%d %s\n",after[tmp].position,dirname[after[tmp].direct+1]);
59 }
60 printf("\n");
61 }
62 return 0;
63 }
标签:
原文地址:http://www.cnblogs.com/alohagin/p/4249713.html