题意:一个长度为L的木棍上有n只蚂蚁,给出了每只蚂蚁的初始位置和朝向,然后蚂蚁开始行走,如果两只蚂蚁相撞,就立刻掉头,直到掉下木棍,问t秒后每只蚂蚁的位置和状态。
题解:因为每只蚂蚁会因为碰撞而掉头,所以相对位置是不变的,为了更容易考虑计算,那么相撞的蚂蚁可以看做是对穿而过,得到输出结果时只要按初始的相对位置再对应上不同的蚂蚁就可以了。
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 10005;
int l, T, n, order[N];
struct Ant {
int dir;
int pos;
int flag;
}sta[N], aft[N];
char s[3][10] = {"L", "Turning", "R"};
int cmp(Ant a, Ant b) {
return a.pos < b.pos;
}
int main() {
int t, cas = 1;
scanf("%d", &t);
while (t--) {
char c;
scanf("%d%d%d", &l, &T, &n);
for (int i = 0; i < n; i++) {
scanf("%d %c", &sta[i].pos, &c);
sta[i].flag = i;
sta[i].dir = (c == 'L' ? -1