记录编号 85718 评测结果 AAAAAAAAAA
题目名称 [UVa 10881] 蚂蚁 最终得分 100
用户昵称 Gravatar超级傲娇的AC酱 是否通过 通过
代码语言 C++ 运行时间 0.171 s
提交时间 2014-01-10 19:56:47 内存使用 0.56 MiB
显示代码纯文本
#include<cstdio>   
#include<algorithm>
using namespace std;  
const int maxn =10000+10;  
struct Ant  
{  
    int no;  
    int s;  
    int t; 
	bool operator <(const Ant& O)const{
		return s<O.s;
	}
}before[maxn],after[maxn];
char turn[][10] = {"L","Turning","R"};  
int order[maxn];
int main()
{
	freopen("Ants.in","r",stdin);
	freopen("Ants.out","w",stdout);
    int t,cas = 1;
    scanf("%d",&t);
    while(t--)
    {
        int L,T,N,i;
        scanf("%d%d%d",&L,&T,&N);
        for(i=0;i<N;i++)
        {
            char c;
            before[i].no=i;
            scanf("%d %c",&before[i].s,&c);
            before[i].t=(c =='L'?-1:1);
            after[i].no =0;
            after[i].s=before[i].s + T*before[i].t;
            after[i].t=before[i].t;
        }
        sort(before,before+N);
        for(i=0;i<N;i++)
        order[before[i].no]=i;
        sort(after,after+N);
        for(i = 0;i<N-1;i++)
        {
            if(after[i].s==after[i+1].s)
            after[i].t=after[i+1].t = 0;
        }
        printf("Case #%d:\n",cas++);
        for(i=0;i<N;i++)
        {
            int a=order[i];
            if(after[a].s<0||after[a].s>L)
            printf("Fell off\n");
            else
            printf("%d %s\n",after[a].s,turn[after[a].t+1]);
        }
        printf("\n");
    }  
    return 0;  
}