Cod sursa(job #2762481)

Utilizator cezar_titianuTitianu Cezar cezar_titianu Data 7 iulie 2021 15:42:48
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#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;
}