Pagini recente » Cod sursa (job #4526) | Monitorul de evaluare | Cod sursa (job #3258027) | Cod sursa (job #3271710) | Cod sursa (job #2875622)
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
static class Task {
public final static String INPUT_FILE = "fractal.in";
public final static String OUTPUT_FILE = "fractal.out";
int n, x, y;
public void solve() {
readInput();
writeOutput(getResult(n, x, y));
}
private void readInput() {
try {
Scanner sc = new Scanner(new File(INPUT_FILE));
n = sc.nextInt();
x = sc.nextInt();
y = sc.nextInt();
sc.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private void writeOutput(int answer) {
try {
PrintWriter pw = new PrintWriter(new File(OUTPUT_FILE));
pw.printf("%d\n", answer);
pw.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private int getResult(int n, int x, int y) {
System.out.println(n + " " + x + " " + y);
if(n==1){
if(x==1 && y==1) return 0;
if(x==1 && y==2) return 1;
if(x==2 && y==1) return 3;
if(x==2 && y==2) return 2;
}
int putere = (int) Math.pow(2,n-1);
int de_adaugat = (int) Math.pow(4,n-1);
if(x>putere){
if(y>putere) {
return 2 * de_adaugat + getResult(n-1,x-putere,y-putere);
}
else {
return 3 * de_adaugat + getResult(n-1,putere-y+1,putere-(x-putere)+1);
}
}
else{
if(y>putere){
return de_adaugat + getResult(n-1,x,y-putere);
}
else {
return getResult(n-1,y,x);
}
}
}
}
public static void main(String[] args) {
new Task().solve();
}
}