Pagini recente » Cod sursa (job #2739605) | Monitorul de evaluare | Cod sursa (job #3212560) | Cod sursa (job #3279796) | Cod sursa (job #2762481)
#include <fstream>
#include <vector>
int main() {
std::ifstream fin("fractal.in");
std::ofstream fout("fractal.out");
int ord, posx, posy;
int ans;
int val, siz, sav;
fin >> ord >> posx >> posy;
posx--;
posy--;
siz = 1;
for (int index = 0; index < ord; index++) {
siz *= 2;
}
val = ord;
ans = 0;
while (val) {
siz /= 2;
val--;
if (posx < siz && posy < siz) {
sav = posx;
posx = posy;
posy = sav;
}
else if (posx < siz && posy >= siz) {
ans += siz * siz;
posy -= siz;
}
else if (posx >= siz && posy >= siz) {
ans += 2 * siz * siz;
posx -= siz;
posy -= siz;
}
else if(posx >= siz && posy < siz) {
ans += 3 * siz * siz;
posx -= siz;
sav = posx;
posx = siz - posy - 1;
posy = siz - sav - 1;
}
}
fout << ans;
}