[BOJ] 드래곤 커브

Date:

[BOJ] 드래곤 커브

Problem URL : 드래곤 커브

#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cstring>
#define p pair<int,int>

using namespace std;

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

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(map, 0, sizeof(map));
	int n, x, y, d, g;
	int endX, endY;
	
	cin >> n;
	while (n--) {
		cin >> x >> y >> d >> g;
		vector<p> v;
		vector<p> nextV;
		endX = x + dx[d];
		endY = y + dy[d];
		map[x][y] = 1;
		map[endX][endY] = 1;
		v.push_back({ x, y });
		v.push_back({ endX, endY });
		while (g--) {
			for (p &current:v) {
				int currentX = current.first;
				int currentY = current.second;
				int nextX = endX - (currentY - endY); //90도 회전 후 X좌표
				int nextY = endY + (currentX - endX); //90도 회전 후 Y좌표				
				map[nextX][nextY] = 1;
				nextV.push_back({ nextX, nextY });
			}
			for (p &current : nextV) {
				v.push_back(current);
			}
			int nextEndX = endX - (y - endY);
			int nextEndY = endY + (x - endX);
			endX = nextEndX;
			endY = nextEndY;
		}
	}
	int ans = 0;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (map[i][j] && map[i][j + 1] && map[i + 1][j] && map[i + 1][j + 1]) {
				ans++;
			}
		}
	}
	cout << ans;
}

댓글