Skip to content

Commit 13b66f7

Browse files
committed
CF1800 A~F
1 parent ea7a105 commit 13b66f7

24 files changed

+740
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package p1800;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Scanner;
5+
6+
public class CF1800A {
7+
public static void main(String[] args) {
8+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
9+
int t = scanner.nextInt();
10+
while (t-- > 0) {
11+
int n = scanner.nextInt();
12+
String s = scanner.next();
13+
System.out.println(solve(n, s));
14+
}
15+
}
16+
17+
private static String solve(int n, String s) {
18+
boolean[] meow = new boolean[4];
19+
char[] cs = s.toLowerCase().toCharArray();
20+
21+
for (int i = 0; i < n; i++) {
22+
if (cs[i] == 'm') {
23+
if (!meow[1] && !meow[2] && !meow[3]) {
24+
meow[0] = true;
25+
} else {
26+
return "NO";
27+
}
28+
} else if (cs[i] == 'e') {
29+
if (meow[0] && !meow[2] && !meow[3]) {
30+
meow[1] = true;
31+
} else {
32+
return "NO";
33+
}
34+
} else if (cs[i] == 'o') {
35+
if (meow[0] && meow[1] && !meow[3]) {
36+
meow[2] = true;
37+
} else {
38+
return "NO";
39+
}
40+
} else if (cs[i] == 'w') {
41+
if (meow[0] && meow[1] && meow[2]) {
42+
meow[3] = true;
43+
} else {
44+
return "NO";
45+
}
46+
} else {
47+
return "NO";
48+
}
49+
}
50+
return meow[0] && meow[1] && meow[2] && meow[3] && cs[n - 1] == 'w' ? "YES" : "NO";
51+
}
52+
}
53+
/*
54+
Codeforces Round 855 (Div. 3)
55+
A. Is It a Cat?
56+
https://codeforces.com/contest/1800/problem/A
57+
58+
题目大意:
59+
给定字符串 s。判断 s 是否是一个 'm', 'e', 'o' 和 'w' 排列。
60+
61+
状态机
62+
======
63+
64+
input
65+
7
66+
4
67+
meOw
68+
14
69+
mMmeoOoWWWwwwW
70+
3
71+
mew
72+
7
73+
MmeEeUw
74+
4
75+
MEOW
76+
6
77+
MmyaVW
78+
5
79+
meowA
80+
81+
output
82+
YES
83+
YES
84+
NO
85+
NO
86+
YES
87+
NO
88+
NO
89+
*/
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package p1800;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import java.util.Scanner;
7+
8+
public class CF1800B {
9+
public static void main(String[] args) {
10+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
11+
int t = scanner.nextInt();
12+
while (t-- > 0) {
13+
int n = scanner.nextInt();
14+
int k = scanner.nextInt();
15+
String s = scanner.next();
16+
System.out.println(solve(n, k, s));
17+
}
18+
}
19+
20+
private static String solve(int n, int k, String s) {
21+
int[] lo = new int[26];
22+
int[] up = new int[26];
23+
for (char ch : s.toCharArray()) {
24+
if (Character.isLowerCase(ch)) {
25+
lo[ch - 'a']++;
26+
} else {
27+
up[ch - 'A']++;
28+
}
29+
}
30+
31+
int res = 0;
32+
// 大小写
33+
for (int i = 0; i < 26; i++) {
34+
int mn = Math.min(lo[i], up[i]);
35+
lo[i] -= mn;
36+
up[i] -= mn;
37+
res += mn;
38+
}
39+
// 大小写转换
40+
for (int i = 0; i < 26; i++) {
41+
int mx = Math.max(lo[i], up[i]) / 2;
42+
int mn = Math.min(k, mx);
43+
k -= mn;
44+
res += mn;
45+
}
46+
return String.valueOf(res);
47+
}
48+
}
49+
/*
50+
B. Count the Number of Pairs
51+
https://codeforces.com/contest/1800/problem/B
52+
53+
题目大意:
54+
给定整数 n, k 和长度为 n 的字符串 s。最多可以转换对 k 个字符做大小写切换。求最大的大小写配对数
55+
56+
贪心。优先队列,能匹配的先匹配完,然后从同一种字符中,每对消耗 1 次转换。
57+
======
58+
59+
input
60+
5
61+
11 2
62+
aAaaBACacbE
63+
2 2
64+
ab
65+
4 1
66+
aaBB
67+
6 0
68+
abBAcC
69+
5 3
70+
cbccb
71+
72+
output
73+
5
74+
0
75+
1
76+
3
77+
2
78+
*/
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package p1800;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Comparator;
5+
import java.util.PriorityQueue;
6+
import java.util.Scanner;
7+
8+
public class CF1800C2 {
9+
public static void main(String[] args) {
10+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
11+
int t = scanner.nextInt();
12+
while (t-- > 0) {
13+
int n = scanner.nextInt();
14+
int[] s = new int[n];
15+
for (int i = 0; i < n; i++) {
16+
s[i] = scanner.nextInt();
17+
}
18+
System.out.println(solve(n, s));
19+
}
20+
}
21+
22+
private static String solve(int n, int[] s) {
23+
PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
24+
long res = 0L;
25+
for (int i = 0; i < n; i++) {
26+
if (s[i] > 0) {
27+
maxHeap.add(s[i]);
28+
} else if (s[i] == 0) {
29+
if (!maxHeap.isEmpty()) {
30+
res += maxHeap.remove();
31+
}
32+
}
33+
}
34+
return String.valueOf(res);
35+
}
36+
}
37+
/*
38+
C2. Powering the Hero (hard version)
39+
https://codeforces.com/contest/1800/problem/C2
40+
41+
题目大意:
42+
给定整数 n 和长度为 n 的数组 s。s[i] = 0 的为英雄牌,s[i] > 0 的为奖励卡,可以加到英雄牌上,然后英雄加到你的军队中,求军队的最大总力量。
43+
44+
贪心。优先队列。遇到英雄牌时,选当前最大的奖励卡加上。
45+
======
46+
47+
input
48+
5
49+
5
50+
3 3 3 0 0
51+
6
52+
0 3 3 0 0 3
53+
7
54+
1 2 3 0 4 5 0
55+
7
56+
1 2 5 0 4 3 0
57+
5
58+
3 1 0 0 4
59+
60+
output
61+
6
62+
6
63+
8
64+
9
65+
4
66+
*/
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package p1800;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Scanner;
5+
6+
public class CF1800D {
7+
public static void main(String[] args) {
8+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
9+
int t = scanner.nextInt();
10+
while (t-- > 0) {
11+
int n = scanner.nextInt();
12+
String s = scanner.next();
13+
System.out.println(solve(n, s));
14+
}
15+
}
16+
17+
private static String solve(int n, String s) {
18+
char[] cs = s.toCharArray();
19+
int res = 1;
20+
for (int i = 0; i + 2 < n; i++) {
21+
if (cs[i] != cs[i + 2]) {
22+
res++;
23+
}
24+
}
25+
return String.valueOf(res);
26+
}
27+
}
28+
/*
29+
D. Remove Two Letters
30+
https://codeforces.com/contest/1800/problem/D
31+
32+
题目大意:
33+
给定整数 n 和长度为 n 的字符串 s。从字符串中删除两个连续的字符。求在这样的操作之后可以获得多少不同的字符串。
34+
35+
枚举每个 s[i] 与 s[i + 2] 是否相等
36+
======
37+
38+
input
39+
7
40+
6
41+
aaabcc
42+
10
43+
aaaaaaaaaa
44+
6
45+
abcdef
46+
7
47+
abacaba
48+
6
49+
cccfff
50+
4
51+
abba
52+
5
53+
ababa
54+
55+
output
56+
4
57+
1
58+
5
59+
3
60+
3
61+
3
62+
1
63+
*/

0 commit comments

Comments
 (0)