CSP 2018-3-2 碰撞的小球

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<bits/stdc++.h>
using namespace std;
int main() {
int N, L, T;
scanf("%d%d%d", &N, &L, &T);
pair<int, int>ball[N + 1];
int line[L+ 1] = { 0 };
for (int i = 1; i <= N; ++i) {
scanf("%d", &ball[i].first);
ball[i].second = 1;
line[ball[i].first] = i;
}
while (T--)
for (int i = 1; i <= N; ++i) {
line[ball[i].first] = 0;
ball[i].first = ball[i].first + ball[i].second;
if (line[ball[i].first] != 0) {
ball[i].second = -ball[i].second;
ball[line[ball[i].first]].second = -ball[line[ball[i].first]].second;
}else if (ball[i].first == 0 || ball[i].first == L)
ball[i].second = -ball[i].second;
line[ball[i].first] = i;
}
for (int i = 1; i <= N; ++i)
printf("%d ", ball[i].first);
return 0;
}

最后更新: 2019年09月02日 11:31

原始链接: http://WangDeqiangCN.github.io/2019/08/31/CSP2018-3-2/

× 请我喝杯咖啡~
打赏二维码