您的位置:首页 > 大数据 > 物联网

UVA 10881(p9)----Piotr's Ants

2016-02-28 19:30 537 查看
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+50;
struct point
{
int id,p,d;
};
int pos[maxn];
point a[maxn],b[maxn];
int cmp(point a,point b)
{
return a.p<b.p;
}
int main()
{
int l,t,n,Case,cas=0;
scanf("%d",&Case);
while(Case--)
{
printf("Case #%d:\n",++cas);
scanf("%d%d%d",&l,&t,&n);
for(int i=0; i<n; i++)
{
char ch;
int x,dir;
scanf("%d %c",&x,&ch);
if(ch=='L') dir=-1;
else dir=1;
b[i].p=x+t*dir;
a[i].id=i;a[i].p=x;
b[i].d=dir;a[i].d=dir;
}
sort(a,a+n,cmp);
sort(b,b+n,cmp);
for(int i=0; i<n; i++)
pos[a[i].id]=i;
for(int i=0; i<n-1; i++)
if(b[i].p==b[i+1].p)
b[i].d=b[i+1].d=0;
for(int i=0; i<n; i++)
{
int num=pos[i];
if(b[num].p<0||b[num].p>l) printf("Fell off\n");
else
{
printf("%d ",b[num].p);
if(b[num].d==0) printf("Turning\n");
else if(b[num].d==1) printf("R\n");
else printf("L\n");
}
}
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: