Skip to content

Commit aee4e2c

Browse files
committed
feat(codeforces): add solutions for p2189C and p2189D1
1 parent 43b624f commit aee4e2c

File tree

5 files changed

+66
-33
lines changed

5 files changed

+66
-33
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.lzw.solutions.codeforces.p2198C;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.io.PrintWriter;
7+
8+
public class Main {
9+
private static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
10+
private static final PrintWriter out = new PrintWriter(System.out, true);
11+
12+
private static void solve() throws IOException {
13+
int t = Integer.parseInt(in.readLine());
14+
for (int test = 0; test < t; test++) {
15+
int n = Integer.parseInt(in.readLine());
16+
int[] p = new int[n];
17+
// Place 1 at the last position
18+
p[n - 1] = 1;
19+
// For positions corresponding to i = 2 to n-1, set p[i-1] = i ^ 1
20+
for (int pos = 1; pos < n - 1; pos++) {
21+
int i = pos + 1;
22+
p[pos] = i ^ 1;
23+
}
24+
// The missing number goes to the first position
25+
if (n % 2 == 0) {
26+
p[0] = n;
27+
} else {
28+
p[0] = n - 1;
29+
}
30+
// Output the permutation
31+
for (int i = 0; i < n; i++) {
32+
out.print(p[i]);
33+
if (i < n - 1) out.print(" ");
34+
}
35+
out.println();
36+
}
37+
}
38+
39+
public static void main(String[] args) throws IOException {
40+
solve();
41+
out.close();
42+
}
43+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.lzw.solutions.codeforces.p2189D1;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.io.PrintWriter;
7+
8+
public class Main {
9+
private static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
10+
private static final PrintWriter out = new PrintWriter(System.out, true);
11+
12+
private static void solve() throws IOException {
13+
// your code here
14+
}
15+
16+
public static void main(String[] args) throws IOException {
17+
solve();
18+
out.close();
19+
}
20+
}

src/main/java/com/lzw/solutions/codeforces/pjava_sample_cf/Main.java

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
3
3+
6

0 commit comments

Comments
 (0)