알고리즘/BOJ

[BOJ 15685] 드래곤 커브

히더 2018. 10. 7. 19:52

백준 :: BOJ :: 15685 :: 드래곤 커브


출처 : https://www.acmicpc.net/problem/15685


#include <bits/stdc++.h>

using namespace std;


struct dc {

int x, y, d, s;

};

int N, ans, arr[101][101]; dc p;

int dx[] = {1,0,-1,0}, dy[] = {0,-1,0,1};

bool visited[101][101];

vector <dc> v; vector <int> dir;


inline bool check(int x, int y) { return arr[y][x] && arr[y + 1][x] && arr[y][x + 1] && arr[y + 1][x + 1] ? true : false; }


void cal() {

dir.push_back(0); dir.push_back(1);

for (int i = 2; i <= 10; i++) {

int m = pow(2, i - 1);

for (int j = 0; j < m; j++) {

if (j < (m / 2)) dir.push_back(dir[j] + 2);

else dir.push_back(dir[j]);

}

}

}


int main() {

std::ios::sync_with_stdio(false); cin.tie(0);

cin >> N; ans = 0;

while (N--) {

cin >> p.x >> p.y >> p.d >> p.s;

v.push_back({p.x,p.y,p.d,p.s});

}


cal();

for (int i = 0; i < v.size(); i++) {

p = v[i];arr[p.y][p.x] = 1;

for (int j = 0; j < pow(2, p.s); j++) {

p.x += dx[(dir[j] + p.d)%4]; p.y += dy[(dir[j] + p.d)%4];

arr[p.y][p.x] = 1;

}

}

for (int i = 0; i < 101; i++) for (int j = 0; j < 101; j++) if (check(j, i)) ans++;


cout << ans;

return 0;

}