Pagini recente » Cod sursa (job #673281) | Cod sursa (job #1817497) | Cod sursa (job #1824230) | Cod sursa (job #643420) | Cod sursa (job #2872368)
#include <iostream>
using namespace std;
FILE *fin = fopen("fractal.in", "r");
FILE *fout = fopen("fractal.out", "w");
int main()
{
int k, x, y;
fscanf(fin, "%d %d %d", &k, &x, &y);
swap(x, y);
long long countt = 0;
while (k >= 0)
{
if (x <= (1 << k) && y <= (1 << k))
{
int aux = x;
x = y;
y = aux;
}
else if (x <= (1 << k) && y > (1 << k))
{
countt += (1 << k) * (1 << k);
y = y - (1 << k);
}
else if (y > (1 << k))
{
countt += (1 << k) * (1 << k) * 2;
y = y - (1 << k);
x = x - (1 << k);
}
else
{
countt += (1 << k) * (1 << k) * 3;
int aux = x;
x = (1 << k) - y + 1;
y = (1 << (k + 1)) - aux + 1;
}
printf("%d %d %d\n", k, x, y);
k--;
}
fprintf(fout, "%lld\n", countt);
}