Skip to content

Commit c72894d

Browse files
committed
灵茶の试炼 * 13
1 parent 71a6f90 commit c72894d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1810
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package p1179;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Scanner;
7+
8+
public class CF1179B {
9+
public static void main(String[] args) {
10+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
11+
int n = scanner.nextInt();
12+
int m = scanner.nextInt();
13+
System.out.println(solve(n, m));
14+
}
15+
16+
private static String solve(int n, int m) {
17+
List<String> resList = new ArrayList<>();
18+
int x1 = 1, y1 = 1, x2 = n, y2 = m;
19+
boolean flag = true;
20+
for (int i = 0; i < n * m; i++) {
21+
resList.add(x1 + " " + y1);
22+
if (flag) {
23+
if (y1 < m) {
24+
y1++;
25+
} else {
26+
x1++;
27+
}
28+
} else {
29+
if (y1 > 1) {
30+
y1--;
31+
} else {
32+
x1++;
33+
}
34+
}
35+
i++;
36+
if (i == n * m) {
37+
break;
38+
}
39+
40+
resList.add(x2 + " " + y2);
41+
if (!flag) {
42+
if (y2 < m) {
43+
y2++;
44+
} else {
45+
x2--;
46+
flag = true;
47+
}
48+
} else {
49+
if (y2 > 1) {
50+
y2--;
51+
} else {
52+
x2--;
53+
flag = false;
54+
}
55+
}
56+
}
57+
return String.join(System.lineSeparator(), resList);
58+
}
59+
}
60+
/*
61+
B. Tolik and His Uncle
62+
https://codeforces.com/contest/1179/problem/B
63+
64+
灵茶の试炼 2023-02-23
65+
题目大意:
66+
输入 n m (n*m≤1e6),表示一个 n 行 m 列的棋盘,行列编号从 1 开始。
67+
初始时,你在 (1,1)。每一步,你可以使用一个方向向量 (dx,dy),然后从当前位置 (x,y) 移动到 (x+dx,y+dy)。
68+
你需要访问每个格子恰好一次,且每一步使用的方向向量互不相同。
69+
如果存在这样的移动方案,输出任意一组符合要求的 n*m 个坐标,表示你每一步所在的位置。否则输出 -1。
70+
71+
constructive algorithms
72+
https://codeforces.com/contest/1179/submission/108111481
73+
提示 1:方案一定存在。
74+
提示 2:从左上角跳到右下角,这个方向向量以后绝不会再用到了。
75+
提示 3:然后再从右下角跳到 (1,2),这个方向向量以后也绝不会再用到了。
76+
======
77+
78+
input
79+
2 3
80+
output
81+
1 1
82+
1 3
83+
1 2
84+
2 2
85+
2 3
86+
2 1
87+
88+
input
89+
1 1
90+
output
91+
1 1
92+
*/
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package p388;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import java.util.Scanner;
8+
9+
public class CF388B {
10+
public static void main(String[] args) {
11+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
12+
int k = scanner.nextInt();
13+
System.out.println(solve(k));
14+
}
15+
16+
// 2^0 ~ 2^29
17+
private static String solve(int num) {
18+
// 1 ~ 92
19+
char[][] adj = new char[93][93];
20+
for (char[] row : adj) {
21+
Arrays.fill(row, 'N');
22+
}
23+
24+
for (int k = 0; k < 30; k++) {
25+
// a1 a - a'
26+
// / | x |
27+
// b1 - b - b'
28+
// ? ?
29+
// c1 c - c'
30+
int a = 3 * k + 3, b = a + 1, c = b + 1;
31+
int a1 = 3 * k, b1 = a1 + 1, c1 = b1 + 1;
32+
// b1-a, b1-b, a-b
33+
adj[b1][a] = adj[a][b1] = 'Y';
34+
adj[b1][b] = adj[b][b1] = 'Y';
35+
adj[a][b] = adj[b][a] = 'Y';
36+
37+
// b 连 c 相当于加上 2^k
38+
if ((num >> k & 1) == 1) {
39+
adj[b][c] = adj[c][b] = 'Y';
40+
}
41+
if (k >= 1) {
42+
// a1-a, a1-b, c1-c
43+
adj[a1][a] = adj[a][a1] = 'Y';
44+
adj[a1][b] = adj[b][a1] = 'Y';
45+
adj[c1][c] = adj[c][c1] = 'Y';
46+
}
47+
}
48+
// 2-92
49+
adj[2][92] = adj[92][2] = 'Y';
50+
51+
List<String> resList = new ArrayList<>();
52+
resList.add("92");
53+
// Consider the graph vertexes are numbered from 1 to n.
54+
for (int i = 1; i < 93; i++) {
55+
resList.add(new String(adj[i]).substring(1));
56+
}
57+
return String.join(System.lineSeparator(), resList);
58+
}
59+
}
60+
/*
61+
B. Fox and Minimal path
62+
https://codeforces.com/contest/388/problem/B
63+
64+
灵茶の试炼 2023-02-28
65+
输入 k(1≤k≤1e9)。
66+
构造一个节点个数不超过 1000 的简单无向图(节点编号从 1 开始),使得从节点 1 到节点 2 的最短路径的数量恰好为 k。
67+
输出 n 以及一个 n*n 的邻接矩阵 g,如果 i 和 j 之间有边,则 g[i][j]='Y',否则为 'N'。
68+
注意不能有自环,即 g[i][i] 必须为 'N'。
69+
70+
constructive algorithms
71+
二进制构造。
72+
k = x1 * 2^0 + x2 * 2^1 + ... + xn * 2^n
73+
======
74+
75+
input
76+
2
77+
output
78+
4
79+
NNYY
80+
NNYY
81+
YYNN
82+
YYNN
83+
84+
input
85+
9
86+
output
87+
8
88+
NNYYYNNN
89+
NNNNNYYY
90+
YNNNNYYY
91+
YNNNNYYY
92+
YNNNNYYY
93+
NYYYYNNN
94+
NYYYYNNN
95+
NYYYYNNN
96+
97+
input
98+
1
99+
output
100+
2
101+
NY
102+
YN
103+
*/
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package p708;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Scanner;
5+
6+
public class CF708B {
7+
private static final String IMPOSSIBLE = "Impossible";
8+
9+
public static void main(String[] args) {
10+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
11+
int a00 = scanner.nextInt();
12+
int a01 = scanner.nextInt();
13+
int a10 = scanner.nextInt();
14+
int a11 = scanner.nextInt();
15+
System.out.println(solve(a00, a01, a10, a11));
16+
}
17+
18+
private static String solve(int a00, int a01, int a10, int a11) {
19+
// 根据 f(0,0) 可以求出 0 的个数 c0,f(0,0) = C(c0, 2)
20+
int cnt0 = f(a00);
21+
int cnt1 = f(a11);
22+
if (cnt0 < 0 || cnt1 < 0) {
23+
return IMPOSSIBLE;
24+
}
25+
26+
if (a01 == 0 && a10 == 0) {
27+
if (a00 > 0 && a11 > 0) {
28+
return IMPOSSIBLE;
29+
} else if (a11 == 0) {
30+
return "0".repeat(cnt0);
31+
} else {
32+
return "1".repeat(cnt1);
33+
}
34+
}
35+
if (a01 + a10 != cnt0 * cnt1) {
36+
return IMPOSSIBLE;
37+
}
38+
39+
int left1 = a10 / cnt0;
40+
int right0 = a10 % cnt0;
41+
String res = "1".repeat(left1) + "0".repeat(cnt0 - right0);
42+
if (right0 > 0) {
43+
res += "1" + "0".repeat(right0);
44+
cnt1--;
45+
}
46+
res += "1".repeat(cnt1 - left1);
47+
return res;
48+
}
49+
50+
// a·x^2 + b·x + c = 0 一元二次方程求根公式 (-b ± sqrt(b^2 - 4ac)) / 2a
51+
// x(x-1)/2 = a
52+
// x = (1 + sqrt(1 + 8a)) / 2
53+
private static int f(long a) {
54+
int x = (int) (1 + Math.sqrt(a * 8 + 1.0) / 2);
55+
if (x * (x - 1L) / 2 == a) {
56+
return x;
57+
}
58+
return -1;
59+
}
60+
}
61+
/*
62+
B. Recover the String
63+
https://codeforces.com/contest/708/problem/B
64+
65+
灵茶の试炼 2023-02-24
66+
题目大意:
67+
对于 01 字符串 s,定义 f(x,y) 表示子序列 [x,y] 在 s 中的出现次数。
68+
输入 f(0,0), f(0,1), f(1,0) 和 f(1,1),范围在 [0,1e9]。
69+
请构造任意一个满足输入的非空字符串 s。
70+
如果不存在,输出 Impossible。
71+
注:子序列是从 s 中删除某些元素得到的。
72+
73+
constructive algorithms
74+
https://codeforces.com/contest/708/submission/194669010
75+
提示 1:根据 f(0,0) 可以求出 0 的个数 c0,因为 f(0,0) = C(c0,2);同理可求出 1 的个数 c1。
76+
提示 2:f(0,1) + f(1,0) = c0 * c1
77+
======
78+
79+
input
80+
1 2 3 4
81+
output
82+
Impossible
83+
84+
input
85+
1 2 2 1
86+
output
87+
0110
88+
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package p1179;
2+
3+
import base.AbstractOjTests;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.io.IOException;
7+
8+
public class CF1179BTests extends AbstractOjTests {
9+
public CF1179BTests() {
10+
super("/p1179/B/");
11+
}
12+
13+
@Test
14+
public void example1() throws IOException {
15+
super.doSetSystemInOut(INPUT1);
16+
CF1179B.main(null);
17+
// 答案不唯一
18+
// super.doAssertion(OUTPUT1);
19+
}
20+
21+
@Test
22+
public void example2() throws IOException {
23+
super.doSetSystemInOut(INPUT2);
24+
CF1179B.main(null);
25+
super.doAssertion(OUTPUT2);
26+
}
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package p388;
2+
3+
import base.AbstractOjTests;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.io.IOException;
7+
8+
public class CF388BTests extends AbstractOjTests {
9+
public CF388BTests() {
10+
super("/p388/B/");
11+
}
12+
13+
@Test
14+
public void example1() throws IOException {
15+
super.doSetSystemInOut(INPUT1);
16+
CF388B.main(null);
17+
// 答案不唯一
18+
// super.doAssertion(OUTPUT1);
19+
}
20+
21+
@Test
22+
public void example2() throws IOException {
23+
super.doSetSystemInOut(INPUT2);
24+
CF388B.main(null);
25+
// 答案不唯一
26+
// super.doAssertion(OUTPUT2);
27+
}
28+
29+
@Test
30+
public void example3() throws IOException {
31+
super.doSetSystemInOut(INPUT3);
32+
CF388B.main(null);
33+
// 答案不唯一
34+
// super.doAssertion(OUTPUT3);
35+
}
36+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package p708;
2+
3+
import base.AbstractOjTests;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.io.IOException;
7+
8+
public class CF708BTests extends AbstractOjTests {
9+
public CF708BTests() {
10+
super("/p708/B/");
11+
}
12+
13+
@Test
14+
public void example1() throws IOException {
15+
super.doSetSystemInOut(INPUT1);
16+
CF708B.main(null);
17+
super.doAssertion(OUTPUT1);
18+
}
19+
20+
@Test
21+
public void example2() throws IOException {
22+
super.doSetSystemInOut(INPUT2);
23+
CF708B.main(null);
24+
// 答案不唯一
25+
// super.doAssertion(OUTPUT2);
26+
}
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1 1
2+
1 3
3+
1 2
4+
2 2
5+
2 3
6+
2 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2

0 commit comments

Comments
 (0)