题解 AT2369【 [AGC013C] Ants on a Circle】 思维题
考虑到原来每只蚂蚁都在相邻之间撞来撞去,所以肯定最后每只蚂蚁的相对顺序是不会改变的。显然可以直接确定最后位置的整个序列,只要确定
不妨想象成蚂蚁相撞,蚂蚁相互穿过,编号交换。
考虑在直线上的情况,直接对应就行了。但现在是在环上,如果有一只蚂蚁逆时针经过
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, l, t, ans[N];
int main() {
scanf("%d%d%d", &n, &l, &t);
int cnt = 0;
for(int i = 0, x, w; i < n; i++){
scanf("%d%d", &x, &w);
x += ((w == 1) ? t : -t);
cnt = ((cnt + (int)floor(1.0 * x / l)) % n + n) % n;
ans[i] = (x % l + l) % l;
}
sort(ans, ans + n);
for(int i = 0; i < n; i++)
printf("%d\n", ans[(cnt + i) % n]);
return 0;
}