-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class Main { | ||
static int N; | ||
static ArrayList<Pair> arrayList; | ||
public static void move(int current, int source, int dest, int aux) { | ||
if(current == 1) { | ||
arrayList.add(new Pair(source, dest)); | ||
}else{ | ||
move(current - 1, source, aux, dest); | ||
arrayList.add(new Pair(source, dest)); | ||
move(current - 1, aux, dest, source); | ||
} | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
N = Integer.parseInt(br.readLine()); | ||
arrayList = new ArrayList<>(); | ||
|
||
move(N, 1, 3, 2); | ||
|
||
System.out.println(arrayList.size()); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
for(Pair p : arrayList) { | ||
sb.append(p.from).append(" "); | ||
sb.append(p.to).append('\n'); | ||
} | ||
|
||
System.out.println(sb); | ||
} | ||
} | ||
|
||
class Pair{ | ||
int from; | ||
int to; | ||
Pair(int f, int t) { | ||
from = f; | ||
to = t; | ||
} | ||
} | ||
|