#include <stdio.h>
#include <stdlib.h>
#include EER 0xffffffff
typedef struct
{
int Distance;
char Dir;
}AntData;
void Ant_go_next(AntData k[],int n,int length); /// one step
int main()
{
int TestCase,i;
int Length,AcoSec,NumAnt;
int calc,Time;
AntData TestOne[100];
scanf("%s",&TestCase);
while(TestCase--)
{
scanf("%d%d%d",&Length,&AcoSec,&NumAnt);
i = 0;
cal =NumAnt;
Time = AcoSec;
while(cal--)
{
scanf("%d%c",&TestOne[i].Distance,&TestOne[i].Dir);
i++;
}
/// sort by Distance
{
;
}
for(int j = 0;j < Time;j++) /// one second one step
{
Ant_go_next(TestOne,NumAnt,Length);
}
/// prompt print
{
;
}
}
return 0;
}
void Ant_go_next(AntData k[],int n,int length) /// one step
{
for(int i = 0;i < n; i++)
{
if((i!=n-1)&&(k[i].Dir!=k[i+1].Dir)&&(k[i].Distance==k[i+1].Distance)) /// right
{
if(k[i].Dir=='R')
{
k[i].Dir = 'L';
k[i].Distance--;
if(k[i].Distance > length || k[i].Distance < 0)
k[i].Distance = EER;
}
if(k[i].Dir=='L')
{
k[i].Dir = 'R';
k[i].Distance++;
if(k[i].Distance > length || k[i].Distance < 0)
k[i].Distance = EER;
}
}
else if((i!=1)&&(k[i].Dir!=k[i-1].Dir)&&(k[i].Distance==k[i-1].Distance)) /// left
{
if(k[i].Dir=='R')
{
k[i].Dir = 'L';
k[i].Distance--;
if(k[i].Distance > length || k[i].Distance < 0)
k[i].Distance = EER;
}
if(k[i].Dir=='L')
{
k[i].Dir = 'R';
k[i].Distance++;
if(k[i].Distance > length || k[i].Distance < 0)
k[i].Distance = EER;
}
else
{
if(k[i].Dir=='R')
{
k[i].Distance++;
if(k[i].Distance > length || k[i].Distance < 0)
k[i].Distance = EER;
}
if(k[i].Dir=='L')
{
k[i].Distance--;
if(k[i].Distance > length || k[i].Distance < 0)
k[i].Distance = EER;
}
}
}
}
觉得另一该留给你完成啦!!!!不合理的地方还请指点!