BNU 26579 Andrew the Ant 蚂蚁问题(二)
return a.s>b.s;
}
int main()
{
int i,len,n,time,left,right,cnt,n1,n2;
while(scanf("%d %d",&len,&n)!=EOF)
{
right=len;
left=0;
for(i=0;i
{
scanf("%d %c",&ant[i].s,&ant[i].flag);
}
sort(ant,ant+n,cmp);
for(i=n-1;i>=0;i--)
if(ant[i].flag=='R')//向右跑
{
right=ant[i].s;
break;
}
for(i=0;i
if(ant[i].flag=='L')//向左跑
{
left=ant[i].s;
break;
}
time=len-right>
left len-right:left;
for(i=0;i
if(ant[i].flag=='R')
aa[i]=ant[i].s+time;
else aa[i]=ant[i].s-time;
sort(aa,aa+n);
cnt=0;
for(i=0;i
{
if(aa[i]==0||aa[i]==len)
{
cnt++;
if(cnt==1) n1=ant[n-1-i].s;
if(cnt==2) n2=ant[n-1-i].s;
}
}
if(cnt==1)
printf("The last ant will fall down in %d seconds - started at %d.\n",time,n1);
else printf("The last ant will fall down in %d seconds - started at %d and %d.\n",time,n1,n2);
}
return 0;
}