# UVa10881题解报告

AC代码：
//#define DEBUG

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<algorithm>

#define MAX 10010
#define ll long long ;
using namespace std;

struct Ant
{
int id;//输入顺序
int p;//位置
int d;//朝向 -1：左，0：转向，1：右
bool operator < (const Ant & a)const {
return p < a.p;
}
}before[MAX],after[MAX];

int order[MAX];//记录顺序

int main() {
ios::sync_with_stdio(false);
int k,count=0;
cin >> k;
int p, d, id;
char tmp;
while (k--) {
int L, T, n;
cin >> L >> T >> n;
for(int i=0;i<n;i++){
cin >> p >> tmp;
d = (tmp == 'L' ? -1 : 1);
before[i]= Ant({i,p,d });
after[i] = Ant({ 0, p + T * d, d });//id要等到sort完,p+T*d:当前位置+时间*方向
}
sort(before, before + n);
for (int i = 0; i < n; i++)//记录输入的蚂蚁位置顺序
order[before[i].id] = i;

sort(after,after + n);
for (int i = 0; i < n-1; i++)
if (after[i].p == after[i+1].p)
after[i].d = after[i+1].d = 0;//置碰撞中的蚂蚁

std::cout<<"Case #"<< ++count << ":\n";
int a;
for (int i = 0; i < n; i++) {
a = order[i];
if (after[a].p<0 || after[a].p>L)//掉出去
cout << "Fell off\n";
else {
cout << after[a].p<<' ';
switch (after[a].d)
{
case -1:cout << "L\n"; break;
case 0:cout << "Turning\n"; break;
case 1:cout << "R\n"; break;
}
}
}
cout << '\n';

}
#ifdef DEBUG
system("pause");
#endif // DEBUG

return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120