git reimport
This commit is contained in:
39
archive/2016.08/2016.08.27 - unsorted/Hanoi.java
Normal file
39
archive/2016.08/2016.08.27 - unsorted/Hanoi.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class Hanoi {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt();
|
||||
int[] a = new int[n];
|
||||
|
||||
String s = in.nextString();
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = s.charAt(i) - 'A';
|
||||
}
|
||||
|
||||
for (int i = n - 1; i >= 0; i--) {
|
||||
if (a[i] == 2) {
|
||||
out.println("NO");
|
||||
return;
|
||||
}
|
||||
|
||||
if (a[i] == 1) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (a[j] < 2) {
|
||||
a[j] = (1 + a[j]) % 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (a[j] > 1) {
|
||||
a[j] = 1 + a[j] % 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.println("YES");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user