File tree Expand file tree Collapse file tree 5 files changed +66
-33
lines changed
java/com/lzw/solutions/codeforces Expand file tree Collapse file tree 5 files changed +66
-33
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Load Diff This file was deleted.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ 2
2+ 3
3+ 6
You can’t perform that action at this time.
0 commit comments