Repository navigation
Expand file tree
/
Copy pathAdvanced Problems.java
More file actions
112 lines (73 loc) · 1.88 KB
/
Copy pathAdvanced Problems.java
File metadata and controls
112 lines (73 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
CSES: Number Spiral
Difficulty: Easy
Pattern: Pattern Recognition + Math
import java.util.Scanner;
public class NumberSpiral {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
long y = sc.nextLong();
long x = sc.nextLong();
long ans;
if (y > x) {
if (y % 2 == 0) {
ans = y * y - x + 1;
} else {
ans = (y - 1) * (y - 1) + x;
}
} else {
if (x % 2 == 0) {
ans = (x - 1) * (x - 1) + y;
} else {
ans = x * x - y + 1;
}
}
System.out.println(ans);
}
sc.close();
}
}
*/
/*
CSES: Two Knights
Difficulty: Medium
Pattern: Math + Combinatorics
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int k = 1; k <= n; k++) {
long total = (long) k * k * (k * k - 1) / 2;
long attacking = 4L * (k - 1) * (k - 2);
long answer = total - attacking;
System.out.println(answer);
}
}
}
*/
/*
CSES: Tower of Hanoi
Difficulty: Easy
Pattern: Recursion
import java.util.*;
public class Main {
static void hanoi(int n, int from, int to, int aux) {
if (n == 0) {
return;
}
hanoi(n - 1, from, aux, to);
System.out.println(from + " " + to);
hanoi(n - 1, aux, to, from);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long moves = (1L << n) - 1;
System.out.println(moves);
hanoi(n, 1, 3, 2);
}
}
*/