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;
}

CSP 2017-12-2 游戏 CSP 2018-3-1 跳一跳

Kommentare

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×