Codeforces 暑期特訓:我想成為演算法大師 - 團練 ICPC Asia Tehran Regional Contest 2022 - Week 8
Luke 我什麼都不會

The 2022 ICPC Asia Tehran Regional Contest

A. Final Price

Problem: A. Final Price

Solution: GitHub Code

1
2
3
4
5
6
7
8
9
10
void solve() {
int n;
cin >> n;
int ans = 0,in;
while(n--){
cin >> in;
ans += in;
}
cout << ans << endl;
}

B. Flower Festival

Problem: B. Flower Festival

Solution: GitHub Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void solve() {
int n;
double far;
cin >> n >> far;
int car;
double time = -1;
for(int i=1;i<=n;i++){
double loc,speed,dis,t;
cin >> loc >> speed;
dis = far - loc;
t = dis / speed;
if(time == -1 or t < time){
time = t;
car = i;
}
}
cout << car << endl;
}

E. Parking Party

Problem: E. Parking Party

Solution: GitHub Code

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
void solve() {
int n, m;
cin >> n >> m;
vector < string > arr(n);
for(int i=0; i<n; i++) cin >> arr[i];

vector < vector < bool > > v(n, vector < bool > (m, false));

int cnt = 0;
// left
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(arr[i][j]=='o') break;
if(!v[i][j]){
cnt++;
v[i][j] = true;
}
}
}
// right
for(int i=0; i<n; i++){
for(int j=m-1; j>=0; j--){
if(arr[i][j]=='o') break;
if(!v[i][j]){
cnt++;
v[i][j] = true;
}
}
}
// up
for(int j=0; j<m; j++){
for(int i=0; i<n; i++){
if(arr[i][j]=='o') break;
if(!v[i][j]){
cnt++;
v[i][j] = true;
}
}
}
// down
for(int j=0; j<m; j++){
for(int i=n-1; i>=0; i--){
if(arr[i][j]=='o') break;
if(!v[i][j]){
cnt++;
v[i][j] = true;
}
}
}

cout << cnt << endl;
}

J. Magic with Cards

Problem: J. Magic with Cards

Solution: GitHub Code

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
28
29
30
31
32
33
34
void solve() {
int n,start,end;
cin >> n >> start >> end;
vector<int> step(2*n+1,-1);
queue<int> next;
next.push(start);
int now = 0;
while(step[end] == -1){
if(next.empty()) break;
int move = next.size();
while(move--){
int go = next.front();
next.pop();
step[go] = now;
int one,two;
if(go <= n){
one = go * 2 - 1;
}
else{
one = (go - n) * 2;
}
if(go%2 == 0){
two = go - 1;
}
else{
two = go + 1;
}
if(step[one] == -1) next.push(one);
if(step[two] == -1) next.push(two);
}
now += 1;
}
cout << step[end] << endl;
}
Powered by Hexo & Theme Keep