Skip to content

Commit f8172a4

Browse files
committed
update
1 parent 2302a73 commit f8172a4

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Time: 327 ms
2+
// Memory: 800 KB
3+
// greedy
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.HashMap;
7+
import java.util.Scanner;
8+
9+
public class Codeforces_2121B_Above_the_Clouds {
10+
public static void main(String[] args) {
11+
Scanner sc = new Scanner(System.in);
12+
int t = sc.nextInt();
13+
for (int i = 0; i < t; i++) {
14+
int n = sc.nextInt();
15+
String s = sc.next();
16+
HashMap<Character, Integer> record = new HashMap<>();
17+
for (int j = 1; j < n - 1; j++) {
18+
record.merge(s.charAt(j), 1, Integer::sum);
19+
}
20+
boolean flag = true;
21+
for (char c : record.keySet()) {
22+
if (record.get(c) > 1) {
23+
flag = false;
24+
break;
25+
}
26+
}
27+
if (flag) {
28+
if (record.containsKey(s.charAt(0)) || record.containsKey(s.charAt(n - 1))) {
29+
flag = false;
30+
}
31+
}
32+
33+
System.out.println(flag ? "NO" : "YES");
34+
}
35+
}
36+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Time: 655 ms
2+
// Memory: 1400 KB
3+
// 可以任意两两比,直至只剩 k 个而 arr[j] 一直不参与。只有一种情况输:k=1 且 arr[j] 不是最大。
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2123B_Tournament {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
int n = sc.nextInt(), j = sc.nextInt(), k = sc.nextInt(), maxVal = -1, indexJ = -1;
14+
for (int r = 0; r < n; r++) {
15+
int a = sc.nextInt();
16+
if (r == j - 1) {
17+
indexJ = a;
18+
}
19+
maxVal = Math.max(maxVal, a);
20+
}
21+
boolean ret = k != 1 || maxVal == indexJ;
22+
23+
System.out.println(ret ? "YES" : "NO");
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)