Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions _munhyeong/1891.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <iostream>
#include <math.h>

using namespace std;

struct Coord {
long double y;
long double x;
};

int main() {
long long d; string shape;
long long x, y;
cin >> d >> shape;
cin >> x >> y;

long double boundary = powl(2, d - 1);
long double step = powl(2, d - 1);

struct Coord cur = { 0, 0 };
for (auto c : shape) {
if (c == '1') {
cur.x += step / 2;
cur.y += step / 2;
}
else if (c == '2') {
cur.x -= step / 2;
cur.y += step / 2;
}
else if (c == '3') {
cur.x -= step / 2;
cur.y -= step / 2;
}
else {
cur.x += step / 2;
cur.y -= step / 2;
}

step /= 2;
}
cur.x += x;
cur.y += y;
if (boundary < abs(cur.y) || boundary < abs(cur.x)) {
cout << -1;
return 0;
}

string answer = "";
step = powl(2, d - 1);
Coord point = { 0, 0 };
for (int i = 0; i < d; i++) {
if (point.y < cur.y && point.x < cur.x) { // 1 사분면
point.x += step / 2;
point.y += step / 2;
answer += "1";
}
else if (point.y < cur.y && point.x > cur.x) { // 2 사분면
point.x -= step / 2;
point.y += step / 2;
answer += "2";
}
else if (point.y > cur.y && point.x > cur.x) { // 3 사분면
point.x -= step / 2;
point.y -= step / 2;
answer += "3";
}
else { // 4 사분면
point.x += step / 2;
point.y -= step / 2;
answer += "4";
}

step /= 2;
}

cout << answer;

return 0;
}