여러개를 그려보면서 커브에대한 규칙을 찾고, 문제 설명에 맞게 구현하는 문제이다.
시험때 만난다면 당황할것같은 ...문제였다.
3~4세대 까지 그리다보면 세대가 증가할 수록 방향 역순으로 +1씩추가됨을 알수있다.
curve.push_back((temp[k] + 1) % 4); //방향 추가
위의 한줄이 핵심코드인것 같다.
이를통해 각각 방문하고,result로 추가하며 출력하면된다.
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int N;
bool visited[101][101];
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,-1,0,1 };
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
int x, y, d, g;
cin >> x >> y >> d >> g;
vector<int> curve; //방향구성
curve.push_back(d);
for (int j = 0; j < g; j++) { //목표세대까지
vector<int> temp = curve;
for (int k = temp.size() - 1; k >= 0; k--) {
curve.push_back((temp[k] + 1) % 4); //방향 추가
}
}
visited[y][x] = true; //시작점
//마지막 세대 가지고있는 방향만큼 더해서 구성
for (int j = 0; j < curve.size(); j++) {
y = y + dy[curve[j]]; //curve[j]:방향가지고있음
x = x + dx[curve[j]];
if (x >= 0 && x < 101 && y >= 0 && y < 101) { //범위내에만
visited[y][x] = true;
}
}
}
int result = 0;
for (int y = 0; y < 100; y++) {
for (int x = 0; x < 100; x++) {
if (visited[y][x] && visited[y][x + 1] && visited[y + 1][x] && visited[y + 1][x + 1]) {
result++;
}
}
}
cout << result;
return 0;
}