[BOJ] 15685번 : 드래곤 커브

2024. 8. 25. 19:58Algorithm

1. problem : 

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

 

2. solution 1 :

#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
int board[102][102];
int n;
int dx[4] = { 1,0,-1,0 }; // 동 -> 북 -> 서 -> 남 // 열 
int dy[4] = { 0,-1,0,1 };  // 행
int ans;

int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	while (n--) {
		int x, y, d, g; 
		cin >> x >> y >> d >> g; //x,y좌표, 방향, 세대
		pair<int, int> cur = { y,x }; 
		vector<int> dir_v; 
		dir_v.push_back(d); 
		int k = 0;
		while (k < g) {
			k++; 
			for (int i = dir_v.size() - 1; i >= 0; i--) {
				dir_v.push_back((dir_v[i] + 1) % 4);
			}
		}
		board[cur.X][cur.Y] = 1;
		for (auto s : dir_v) {
			cur.X += dy[s];
			cur.Y += dx[s]; 
			board[cur.X][cur.Y] = 1; 
		}
	}
	for (int i = 0; i <= 99; i++) {
		for (int j = 0; j <= 99; j++) {
			if (board[i][j] && board[i][j + 1] && board[i + 1][j] && board[i + 1][j + 1]) ans++;
		}
	}
	cout << ans << '\n';
}

 

'Algorithm' 카테고리의 다른 글

[BOJ] 2751번 : 수 정렬하기 2  (0) 2024.08.26
[BOJ] 11728번 : 배열 합치기  (0) 2024.08.25
[BOJ] 14889번 : 스타트와 링크  (0) 2024.08.24
[BOJ] 14888번 연산자 끼워넣기  (0) 2024.08.24
[BOJ] 14502번 : 연구소  (0) 2024.08.24