Codeforces Round 957 (Div.3)

7月11日 Codeforces 实战记录。(1461 -> 1505)

AC数5/7
比赛跳转:Codeforces Round 957 (Div. 3)

题解

A. Only Pluses

分析:每次给最小的数 +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
#include<bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
int x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
return x * f;
}

void solve(){
vector<int>v(3);
cin >> v[0] >> v[1] >> v[2];
for(int i = 1; i <= 5; i++){
sort(v.begin(), v.end());
v[0]++;
}
cout << v[0] * v[1] * v[2] << '\n';
}

signed main(){
int t = read();
while(t--) solve();
return 0;
}

B. Angry Monk

分析:保留最大数,其他数加入最大数,n - 1 次拆成全1,n 次合并,对每个数计 2n - 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
#include<bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
int x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
return x * f;
}

void solve(){
int n = read(), k = read();
vector<int>v(k);
for(auto &i : v) i = read();

sort(v.begin(), v.end());
int res = 0;
for(int i = 0; i < k - 1; i++){
res += v[i] + v[i] - 1;
}
cout << res << '\n';
}

signed main(){
int t = read();
while(t--) solve();
return 0;
}

C. Gorilla and Permutation

分析:构造题,给 >= k 的数分配尽可能大的权重,放在序列开头部分(降序), <= m 的数分配尽可能小的权重,放在序列尾端部分(升序)

如果一个数同时满足这两个条件,则不会被计入权重,应该将其放在序列中间部分,保证尾端部分的权重更小。

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
#include<bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
int x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
return x * f;
}

void solve(){
int n = read(), m = read(), k = read();
int mid = min(k - 1, m);
for(int i = n; i > mid; i--){
cout << i << ' ';
}
for(int i = 1; i <= mid; i++){
cout << i << ' ';
}
puts("");
}

signed main(){
int t = read();
while(t--) solve();
return 0;
}

D. Test of Love

模拟题:贪心,先尽可能跳到 L 上,如果不行,跳到尽可能远的 W 里,游动,重复此过程。

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
59
60
61
62
63
64
65
66
67
68
69
70
#include<bits/stdc++.h>
#define int long long
using namespace std;

inline int read() {
int x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
return x * f;
}

void solve() {
int n = read(), m = read(), k = read();
string s; cin >> s; s = "L" + s;

int cntw = 0;
for (int i = 0; i <= n;) {

int ok = 0;
for (int j = m; j > 0; j--) {
if (s[i + j] == 'L') {
i += j;
ok = 1;
break;
}
}

if (i + m >= n + 1) {
cout << "YES" << '\n';
return;
}

if (!ok) {
for (int j = m; j > 0; j--) {
if (s[i + j] == 'W') {
i += j;
ok = 2;
break;
}
}
}

if (ok == 0) {
cout << "NO" << '\n';
return;
}
else if (ok == 1) {
continue;
}

while (s[i] == 'W') {
i++;
cntw++;
if (cntw > k || s[i] == 'C') {
cout << "NO" << '\n';
return;
}
if (i == n + 1) {
cout << "YES" << '\n';
return;
}
}
}
}

signed main() {
int t = read();
while (t--) solve();
return 0;
}

E. Novice’s Mistake

分析:模拟题意即可,注意控制 b 的范围避免不必要情况。

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
#include<bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
int x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
return x * f;
}

int get(string& str, int len) {
int x = 0;
for (int i = 0; i < len; i++) {
x = x * 10 + str[i] - 48;
}
return x;
}

void solve(){
int n = read();
int cnt = 0;
vector<pair<int, int>> ans;
string s = to_string(n);
string str = "";
for (int a = 1; a <= 10000; a++) {
str += s;

int len = str.length();
int maxb = min({ (long long)10000, a * n, len - 1 });
for (int b = max((long long)1, len - 10); b <= maxb; b++) {
if (get(str, len - b) == a * n - b) {
cnt++;
ans.emplace_back(a, b);
}
}
}
cout << cnt << '\n';
for(auto [a, b] : ans){
cout << a << ' ' << b << '\n';
}
}

signed main(){
int t = read();
while(t--) solve();
return 0;
}