Pagini recente » Cod sursa (job #3237038) | Cod sursa (job #1918578) | Cod sursa (job #2234051) | Cod sursa (job #1851961) | Cod sursa (job #1978793)
#include <fstream>
using namespace std;
int x, y;
int fractal(int k){
int pow = 1 << k;
if (!k)
return 0;
else
if (x <= pow / 2 && y <= pow / 2){ //cadr I
x = x + y;
y = x - y;
x = x - y;
return fractal(k - 1);
}
else
if (x <= pow / 2 && y > pow / 2){ //cadr II
y -= pow / 2;
return (pow / 2 * pow / 2) + fractal(k - 1);
}
else
if (x > pow / 2 && y > pow / 2){ //cadr III
y -= pow / 2;
x -= pow / 2;
return (pow / 2 * pow / 2) * 2 + fractal(k - 1);
}
else
if (x > pow / 2 && y <= pow / 2){ //cadr IV
y = pow / 2 - y + 1;
x = pow - x + 1;
x = x + y;
y = x - y;
x = x - y;
return (pow / 2 * pow / 2) * 3 + fractal(k - 1);
}
}
int main(){
int k;
ifstream citire ("fractal.in");
citire >> k >> x >> y;
citire.close();
ofstream afisare ("fractal.out");
afisare << fractal(k);
afisare.close();
return 0;
}