Skip to content

Commit 6ea9897

Browse files
committed
CF1790 A~E
1 parent 99cf8af commit 6ea9897

File tree

20 files changed

+568
-0
lines changed

20 files changed

+568
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package p1790;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Scanner;
5+
6+
public class CF1790A {
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+
String n = scanner.next();
12+
System.out.println(solve(n));
13+
}
14+
}
15+
16+
private static String solve(String n) {
17+
String T = "314159265358979323846264338327";
18+
int i = 0;
19+
for (; i < n.length(); i++) {
20+
if (n.charAt(i) != T.charAt(i)) {
21+
return String.valueOf(i);
22+
}
23+
}
24+
return String.valueOf(i);
25+
}
26+
}
27+
/*
28+
Codeforces Round #847 (Div. 3)
29+
A. Polycarp and the Day of Pi
30+
https://codeforces.com/contest/1790/problem/A
31+
32+
题目大意:
33+
给定字符串 n。计算 n 是圆周率的前多少个字母
34+
35+
模拟。
36+
======
37+
38+
input
39+
9
40+
000
41+
3
42+
4141592653
43+
141592653589793238462643383279
44+
31420
45+
31415
46+
314159265358
47+
27182
48+
314159265358979323846264338327
49+
50+
output
51+
0
52+
1
53+
0
54+
0
55+
3
56+
5
57+
12
58+
0
59+
30
60+
*/
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package p1790;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Arrays;
5+
import java.util.Scanner;
6+
import java.util.stream.Collectors;
7+
8+
public class CF1790B {
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 = scanner.nextInt();
15+
int r = scanner.nextInt();
16+
System.out.println(solve(n, s, r));
17+
}
18+
}
19+
20+
private static String solve(int n, int s, int r) {
21+
int max = s - r;
22+
int[] res = new int[n];
23+
Arrays.fill(res, r / (n - 1));
24+
res[n - 1] = max;
25+
for (int i = 0; i < r % (n - 1); i++) {
26+
res[i]++;
27+
}
28+
return Arrays.stream(res).mapToObj(String::valueOf).collect(Collectors.joining(" "));
29+
}
30+
}
31+
/*
32+
B. Taisia and Dice
33+
https://codeforces.com/contest/1790/problem/B
34+
35+
题目大意:
36+
给定整数 n,s,r。骰子掷了 n 次,点数和为 s,除去最大一个点数,其余点数和为 r,求原序列。
37+
38+
p[n-1] = s - r;其余为 r / (n-1);余数随机散落
39+
======
40+
41+
input
42+
7
43+
2 2 1
44+
2 4 2
45+
4 9 5
46+
5 17 11
47+
3 15 10
48+
4 4 3
49+
5 20 15
50+
51+
output
52+
1 1
53+
2 2
54+
1 2 2 4
55+
6 4 2 3 2
56+
5 5 5
57+
1 1 1 1
58+
1 4 5 5 5
59+
*/
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package p1790;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Arrays;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.Scanner;
8+
import java.util.stream.Collectors;
9+
10+
public class CF1790C {
11+
public static void main(String[] args) {
12+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
13+
int t = scanner.nextInt();
14+
while (t-- > 0) {
15+
int n = scanner.nextInt();
16+
int[][] p = new int[n][n - 1];
17+
for (int i = 0; i < n; i++) {
18+
for (int j = 0; j < n - 1; j++) {
19+
p[i][j] = scanner.nextInt();
20+
}
21+
}
22+
System.out.println(solve(n, p));
23+
}
24+
}
25+
26+
private static String solve(int n, int[][] p) {
27+
Map<Integer, Integer> cntMap = new HashMap<>();
28+
for (int i = 0; i < n; i++) {
29+
int x = p[i][0];
30+
cntMap.put(x, cntMap.getOrDefault(x, 0) + 1);
31+
}
32+
int first = -1;
33+
int sec = -1;
34+
for (Map.Entry<Integer, Integer> entry : cntMap.entrySet()) {
35+
if (entry.getValue() > 1) {
36+
first = entry.getKey();
37+
} else {
38+
sec = entry.getKey();
39+
}
40+
}
41+
int[] res = new int[n];
42+
res[0] = first;
43+
for (int i = 0; i < n; i++) {
44+
int x = p[i][0];
45+
if (x == sec) {
46+
System.arraycopy(p[i], 0, res, 1, n - 1);
47+
break;
48+
}
49+
}
50+
return Arrays.stream(res).mapToObj(String::valueOf).collect(Collectors.joining(" "));
51+
}
52+
}
53+
/*
54+
C. Premutation
55+
https://codeforces.com/contest/1790/problem/C
56+
57+
题目大意:
58+
给定整数 n 和 n 行,每行 n-1 个数,每行跳过了元素 pi,pi 不重复,不知道它们被写的顺序,要求重建原来的序列
59+
60+
首位必定出现 n-1 次,后面加上一个仅出现 1 次的序列即可。
61+
======
62+
63+
input
64+
5
65+
4
66+
4 2 1
67+
4 2 3
68+
2 1 3
69+
4 1 3
70+
3
71+
2 3
72+
1 3
73+
1 2
74+
5
75+
4 2 1 3
76+
2 1 3 5
77+
4 2 3 5
78+
4 1 3 5
79+
4 2 1 5
80+
4
81+
2 3 4
82+
1 3 4
83+
1 2 3
84+
1 2 4
85+
3
86+
2 1
87+
1 3
88+
2 3
89+
90+
output
91+
4 2 1 3
92+
1 2 3
93+
4 2 1 3 5
94+
1 2 3 4
95+
2 1 3
96+
*/
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package p1790;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Scanner;
5+
import java.util.TreeMap;
6+
7+
public class CF1790D {
8+
public static void main(String[] args) {
9+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
10+
int t = scanner.nextInt();
11+
while (t-- > 0) {
12+
int n = scanner.nextInt();
13+
int[] a = new int[n];
14+
for (int i = 0; i < n; i++) {
15+
a[i] = scanner.nextInt();
16+
}
17+
System.out.println(solve(n, a));
18+
}
19+
}
20+
21+
private static String solve(int n, int[] a) {
22+
TreeMap<Integer, Integer> cntMap = new TreeMap<>();
23+
for (int ai : a) {
24+
cntMap.put(ai, cntMap.getOrDefault(ai, 0) + 1);
25+
}
26+
27+
int res = 0;
28+
while (cntMap.size() > 0) {
29+
int first = cntMap.firstKey();
30+
// 连续取
31+
for (int doll = first; cntMap.containsKey(doll); doll++) {
32+
int cnt = cntMap.get(doll);
33+
if (cnt == 1) {
34+
cntMap.remove(doll);
35+
} else {
36+
cntMap.put(doll, cnt - 1);
37+
}
38+
}
39+
res++;
40+
}
41+
return String.valueOf(res);
42+
}
43+
}
44+
/*
45+
D. Matryoshkas
46+
https://codeforces.com/contest/1790/problem/D
47+
48+
题目大意:
49+
给定整数 n 和长度为 n 的数组 a。俄罗斯套娃每次+1,求至少有多少套
50+
51+
相似题目: 846. 一手顺子
52+
https://leetcode.cn/problems/hand-of-straights/
53+
======
54+
55+
input
56+
10
57+
6
58+
2 2 3 4 3 1
59+
5
60+
11 8 7 10 9
61+
6
62+
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
63+
8
64+
1 1 4 4 2 3 2 3
65+
6
66+
1 2 3 2 3 4
67+
7
68+
10 11 11 12 12 13 13
69+
7
70+
8 8 9 9 10 10 11
71+
8
72+
4 14 5 15 6 16 7 17
73+
8
74+
5 15 6 14 8 12 9 11
75+
5
76+
4 2 2 3 4
77+
78+
output
79+
2
80+
1
81+
6
82+
2
83+
2
84+
2
85+
2
86+
2
87+
4
88+
3
89+
*/
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package p1790;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Scanner;
5+
6+
public class CF1790E {
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 x = scanner.nextInt();
12+
System.out.println(solve(x));
13+
}
14+
}
15+
16+
private static String solve(int x) {
17+
// a-b = x
18+
// a+b = 2x
19+
// a = 3x / 2
20+
long x3 = x * 3L;
21+
if (x3 % 2 != 0) {
22+
return "-1";
23+
} else {
24+
long a = x3 / 2;
25+
long b = a - x;
26+
if ((a ^ b) != x) {
27+
return "-1";
28+
}
29+
return a + " " + b;
30+
}
31+
}
32+
}
33+
/*
34+
E. Vlad and a Pair of Numbers
35+
https://codeforces.com/contest/1790/problem/E
36+
37+
题目大意:
38+
给定整数 x。x = a ^ b = (a+b)/2
39+
40+
位运算性质。a ^ b 可以看作 a - b。解方程再判断即可。
41+
======
42+
43+
input
44+
6
45+
2
46+
5
47+
10
48+
6
49+
18
50+
36
51+
52+
output
53+
3 1
54+
-1
55+
13 7
56+
-1
57+
25 11
58+
50 22
59+
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package p1790;
2+
3+
import base.AbstractOjTests;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.io.IOException;
7+
8+
public class CF1790ATests extends AbstractOjTests {
9+
public CF1790ATests() {
10+
super("/p1790/A/");
11+
}
12+
13+
@Test
14+
public void example1() throws IOException {
15+
super.doSetSystemInOut();
16+
CF1790A.main(null);
17+
super.doAssertion();
18+
}
19+
}

0 commit comments

Comments
 (0)