Cod sursa(job #2975136)
Utilizator | Matt . matthriscu | Data | 5 februarie 2023 15:56:02 |
---|---|---|---|
Problema | Fractal | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.49 kb |
#include <bits/stdc++.h>
using namespace std;
int hilbert (int k, int x, int y) {
int ans = 0;
for (int i = k >> 1; i; i >>= 1) {
bool rx = x & i, ry = y & i;
ans += i * i * ((3 * rx) ^ ry);
if (!ry) {
if (rx) {
x = k - 1 - x;
y = k - 1 - y;
}
swap(x, y);
}
}
return ans;
}
int main() {
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int k, x, y;
fin >> k >> x >> y;
fout << hilbert(1 << k, x - 1, y - 1) << '\n';
}