Topic link
For each ant, he relative to the position of other ants is fixed, catch up front or be behind the catch-up are going back, so, the assumption that the stick is infinitely long, in the first always in the first place, the second is always in second place. At the same time, every two ants in the meeting are like exchanging identities and moving on. So, regardless of their meeting, let each go along the route. As you can see from the front, the order in which the final state of each ant is arranged is the number of the first ant.
#include <map> #include <set> #include <cstdio> #include <cstring> #include <algorithm> # Include <queue> #include <iostream> #include <stack> #include <cmath> #include <string> # Include <vector> #include <cstdlib>//#include <bits/stdc++.h>//#define LOACL #define SPACE "" #define Lson o<<1, L, Mid #define Rson o<<1|1, mid+1, R #define LL o<<1 #define RR o<<1|1 using namespace
Std
typedef long Long LL;
typedef unsigned long UL;
typedef __int64 INT;
typedef pair<int, int> PAI;
const int INF = 0X3F3F3F3F;
Const double ESP = 1e-5;
Const double PI = ACOs (-1.0);
const int MOD = 1e9 + 7;
const int MAXN = 10000 + 10;
struct ant {int dic;
int S, E;
int id;
} DATA[MAXN];
int F[MAXN];
Char str[][10] = {"L", "turning", "R", "Fell off"};
BOOL CMP (ant x, ant y) {return X.E < Y.E] bool Cmp1 (ant x, ant y) {return x.s < Y.S;} int main () {int T;
Char s[10]; scanf ("%d", &t);
int kcase = 0;
while (t--) {int L, T, N;
scanf ("%d%d%d", &l, &t, &n);
for (int i = 0; i < N; i++) {scanf ("%d%s", &data[i].s, s);
Data[i].dic = (S[0] = = ' R '? 1:-1);
Data[i].id = i;
DATA[I].E = Data[i].s + data[i].dic*t;
Sort (data, data + N, CMP1);
for (int i = 0; i < N; i++) f[data[i].id] = i;
Sort (data, data + N, CMP);
for (int i = 0; i < N; i++) {if (data[i].e < 0 | | | data[i].e > L) data[i].dic = 2;
else if (i!= 0 && data[i].e = = data[i-1].e) data[i].dic = data[i-1].dic = 0;
printf ("Case #%d:\n", ++kcase);
for (int i = 0; i < N; i++) {int u = f[i];
int v = data[u].dic;
if (v = = 2) printf ("Fell off\n");
else printf ("%d%s\n", DATA[U].E, str[v+1]);
printf ("\ n"); } return0; }