반응형
https://www.acmicpc.net/problem/15685
15685번: 드래곤 커브
첫째 줄에 드래곤 커브의 개수 N(1 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에는 드래곤 커브의 정보가 주어진다. 드래곤 커브의 정보는 네 정수 x, y, d, g로 이루어져 있다. x와 y는 드래곤 커
www.acmicpc.net
1.문제설명
드래곤 커브가 움직이는 방향을 기준을 바탕으로
드래곤 커브 규칙에 따라 지나는 지점을 표시한 후
사각형을 검사하면서 네 꼭짓점이 모두 지나간 점인지 확인해서 풀 수 있다.
2.문제풀이코드 C++
#include <bits/stdc++.h>
using namespace std;
int N;
bool point[103][103];
//방향벡터 모음
// 0 -> 90도회전: 1
// 0 1 -> 90도회전 : 1 2
// 0 1 2 1 -> 90도 회전 : 1 2 3 2
// 0 1 2 1 2 3 2 1
vector<int> getDirectionVector(int d, int g){
vector<int> direction;
direction.push_back(d);
//90도 회전하고 역순으로 추가 g번반복
for(int i=0; i<g; i++){
vector<int> newDirection;
for(int j=0; j<direction.size(); j++){
newDirection.push_back((direction[j]+1)%4);
}
for(int j=direction.size()-1; j>=0; j--){
direction.push_back(newDirection[j]);
}
}
return direction;
}
void dotPoint(int x, int y, const vector<int>& direction){
int curX = x, curY = y;
point[curX][curY] = 1;
for(int i=0; i<direction.size();i++){
if(direction[i]==0){
curY += 1;
}
else if(direction[i]==1){
curX -= 1;
}
else if(direction[i]==2){
curY -= 1;
}
else if(direction[i]==3){
curX += 1;
}
point[curX][curY] = 1;
}
}
int countRectangle(){
int ans = 0;
for(int i=0; i<=99; i++){
for(int j=0; j<=99; j++){
if(point[i][j] && point[i+1][j] && point[i][j+1] && point[i+1][j+1]){
ans++;
}
}
}
return ans;
}
void dragonCurve(int x, int y, int d, int g){
vector<int> direction = getDirectionVector(d,g);
dotPoint(x,y, direction);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for(int i=0; i<N; i++){
int x, y, d, g;
cin >> x >> y >> d >> g;
dragonCurve(y,x,d,g);
}
cout << countRectangle() << '\n';
return 0;
}
반응형
'Algorithm > problem' 카테고리의 다른 글
백준 17779번 : 게리맨더링 2 - brute Force cpp (0) | 2022.07.10 |
---|---|
백준 17471번 : 게리맨더링 : 완전탐색, BFS - Cpp (0) | 2022.07.10 |
백준 16434번 : 드래곤 앤 던전 - 이분탐색, 구현 C++ (0) | 2022.07.04 |
백준 6236번 : 용돈 관리 - 이분탐색(매개변수 탐색) C++ (0) | 2022.07.03 |
백준 2343: 기타레슨 - 이분탐색(Parameter Searche) C++ (0) | 2022.07.03 |