Codeforces 暑期特訓:我想成為演算法大師 - 2024 TOPC - Week 11
Luke 我什麼都不會

2024 ICPC Asia Taiwan Online Programming Contest

A. Animal Farm

Problem: A. Animal Farm

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
signed main(){
int n;
cin >> n;

vector < string > a(n);
vector < int > b(n);
for(int i=0; i<n; i++){
cin >> a[i] >> b[i];
}

int m = 0;
for(int i=0; i<n; i++){
if(a[i]=="pig"){
m = max(m, b[i]);
}
}

int ans = m;
for(int i=0; i<n; i++){
if(a[i]!="pig" and b[i]<m){
ans += b[i];
}
}
cout << ans << endl;
}

J. Just Round Down

Problem: J. Just Round Down

Solution: GitHub Code

1
2
x = float(input())
print(int(x))

K. Kingdom’s Development Plan

Problem: K. Kingdom’s Development Plan

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 < vector < int > > G(n);
vector < int > unlock(n, 0);
int u, v;
FOR(i, 0, m){
cin >> u >> v;
u--; v--;
G[u].PB(v);
unlock[v]++;
}

vector < bool > visit(n, false);
vector < int > ans;
prior < int > q;
FOR(i, 0, n){
if(unlock[i]==0){
q.push(i);
// visit[i] = true;
// ans.PB(i);
}
}

while(!q.empty()){
int x = q.top();
q.pop();
// cout << x << endl;

visit[x] = true;
ans.PB(x);

for(int y: G[x]){
unlock[y]--;
if(unlock[y]==0){
q.push(y);
// visit[y] = true;
// ans.PB(y);
}
}
}

if(ans.size()==n){
for(int i: ans){
cout << i+1 << ' ';
}
cout << endl;
}else{
cout << "IMPOSSIBLE" << endl;
}
}
Powered by Hexo & Theme Keep