AtCoder Beginner Contest 222
A - Four Digits
问题陈述
给你一个介于\(0\) 和\(9999\) (含)之间的整数\(N\) 。
在该整数上添加必要数量的前导零后,将其打印为一个四位数字符串。
1 2 3 4 5 6 7 8 9 #include <bits/stdc++.h> using namespace std;int main () { int x; cin>>x; printf ("%04d" ,x); return 0 ; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <bits/stdc++.h> using namespace std;int main () { ios::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); string s; cin >> s; for (int i = 0 ; i < 4 -s.size (); i++) { cout << '0' ; } cout << s <<'\n' ; return 0 ; }
B - Failing Grade
问题陈述
有 \(N\)
名学生参加考试。学生标记为学生\(1\) 、学生\(2\) 、学生\(\dots\) 、学生\(N\) ,学生\(i\) 得了\(a_i\) 分。
得分低于\(P\) 分的学生被视为考试不及格,不能获得学分。求不及格的学生人数。
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 #include <bits/stdc++.h> using namespace std;int main (void ) { ios::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); int n, p, x, cnt = 0 ; cin >> n >> p; for (int i = 1 ; i <= n; i++) { cin >> x; cnt += x < p; } cout << cnt << '\n' ; return 0 ; } #include <bits/stdc++.h> using namespace std; typedef long long ll;typedef unsigned long long ull;ll ans; int main () { ios::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); int n, p; cin >> n >> p; for (int i = 1 ; i <= n; i++) { int op; cin >> op; if (op < p) ans++; } cout << ans << endl; }
C - Swiss-System
Tournament
问题陈述
编号为 \(1\) 至 \(2N\) 的 \(2N\) 名选手将参加剪刀石头布比赛。
比赛共有 \(M\) 轮。每轮比赛有 \(N\)
场一对一比赛,每位选手参加其中一场。
每\(i=0, 1, \ldots,
M\) 场比赛结束时,选手的排名按以下方式确定。
在前\(i\) 轮比赛中获胜次数多的棋手排名靠前。
平局由 ID 编号决定:ID 编号较小的棋手排名靠前。
此外,对于每个\(i=1, \ldots,
M\) ,\(i\) /th回合的比赛安排如下。
对于每个\(k=1, 2, \ldots,
N\) ,在\((i-1)\) /th回合结束时排名\((2k-1)\) /th和\(2k\) /th的棋手之间会进行一场比赛。
在每场比赛中,两位棋手只下一手牌,结果是一方赢,另一方输,或者平局。
能够预知未来的高桥(Takahashi)知道棋手\(i\) 将在\(j\) /th轮的比赛中与\(A_{i, j}\) 下棋,其中\(A_{i,j}\) 是 "G"、"C "或 "P"。
这里,"G "代表石头,"C "代表剪刀,"P
"代表纸。(源自日语)__________________________。
在\(M\) (-)轮结束时找出玩家的等级。
剪刀石头布的规则 剪石头布比赛的结果是根据双方的出牌情况决定的。
如果一方出石头(G),另一方出剪刀(C),出石头(G)的一方获胜。
如果一方出剪刀(C),另一方出纸(P),则出剪刀(C)的一方获胜。
如果一方出纸(P),另一方出石头(G),出纸(P)的一方获胜。
如果双方出相同的牌,则平局。
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 53 54 55 56 57 58 #include <bits/stdc++.h> using namespace std;string a[110 ]; int ans[110 ];bool cmp (pair<int , int > a, pair<int , int > b) { if (a.first == b.first) return a.second < b.second; else return a.first > b.first; } int main (void ) { ios::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); int n, m; vector<pair<int , int >> vt; cin >> n >> m; for (int i = 0 ; i < n * 2 ; i++) { cin >> a[i]; vt.push_back ({0 , i}); } for (int i = 0 ; i < m; i++) { sort (vt.begin (), vt.end (), cmp); for (int j = 0 ; j < n; j++) { int p1 = vt[2 * j].second, p2 = vt[2 * j + 1 ].second; char cha = a[p1][i], chb = a[p2][i]; if (cha == chb) { continue ; } else { string v; v += cha; v += chb; if (v == "GC" || v == "CP" || v == "PG" ) { vt[2 * j].first++; } else { vt[2 * j + 1 ].first++; } } } } sort (vt.begin (), vt.end (), cmp); for (auto it : vt) { cout << it.second + 1 << '\n' ; } return 0 ; }
D - Between Two
Arrays
问题陈述
当且仅当\(s_i \leq
s_{i+1}\) 对每一个\(i\) 成立时,\(S =
(s_1, s_2, \dots, s_n)\) 的\(n\) 数列被称为_非递减_数列。\((1 \leq i \leq n - 1)\) .
给定的是 \(N\)
个整数的非递减序列:\(A = (a_1, a_2, \dots,
a_N)\) 和 \(B = (b_1, b_2, \dots,
b_N)\) 。
考虑一个非递减的\(N\) 整数序列\(C = (c_1, c_2, \dots,
c_N)\) ,它满足以下条件:
\(a_i \leq c_i \leq b_i\) 对于每个
\(i\) \((1
\leq i \leq N)\) .
求模数为 \(998244353\)
的序列中可以有 \(C\) 的序列个数。 \[
对于当前第
i
个数,它可以由当前位比它小的数叠加过来,即
d
p
[
i
]
[
j
]
+
=
d
p
[
i
]
[
j
−
1
]
,另外一部分可以由上一位的最大数累加过来,但是上一位的当前数不能大于当前位的数,即
d
p
[
i
]
[
j
]
+
=
d
p
[
i
−
1
]
[
m
i
n
(
j
,
b
[
i
−
1
]
)
]
\]
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 #include <bits/stdc++.h> using namespace std;using ll=long long ;const int maxn = 3005 ;const int mod = 998244353 ;ll dp[maxn][maxn]; int a[maxn], b[maxn];int main () { ios::sync_with_stdio (false ); cin.tie (0 ); cout.tie (0 ); int n; cin >> n; for (int i = 1 ; i <= n; i++) cin >> a[i]; for (int i = 1 ; i <= n; i++) cin >> b[i]; for (int i = a[1 ]; i <= b[1 ]; i++) { dp[1 ][i] = i - a[1 ] + 1 ; } for (int i = 2 ; i <= n; i++) { for (int j = a[i]; j <= b[i]; j++) { dp[i][j] += dp[i][j - 1 ] + dp[i - 1 ][min (j, b[i - 1 ])]; dp[i][j] %= mod; } } cout << dp[n][b[n]] << '\n' ; }