https://www.acmicpc.net/problem/15685
15685번: 드래곤 커브
첫째 줄에 드래곤 커브의 개수 N(1 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에는 드래곤 커브의 정보가 주어진다. 드래곤 커브의 정보는 네 정수 x, y, d, g로 이루어져 있다. x와 y는 드래곤 커
www.acmicpc.net
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int MAX = 101;
int map[MAX][MAX];
int n;
struct INFO { int x, y,d,g; };
vector<INFO> startp;
vector<vector<int>> way;
struct MOVE { int x, y; };
MOVE mv[4] = { {0,1}, {-1,0}, {0,-1}, {1,0} };
int answer = 0;
void MoveDragon(int index) {
way[index].push_back(startp[index].d);
map[startp[index].x][startp[index].y] = 1;
int movei = startp[index].x + mv[startp[index].d].x;
int movej = startp[index].y + mv[startp[index].d].y;
startp[index] = { movei,movej,-1,startp[index].g };
map[movei][movej] = 1;
for (int i = 1; i <= startp[index].g; i++) { //세대
int sz = way[index].size();
for (int k = sz-1; k >=0; k--) {
int dir = way[index][k]+ 1;
if (dir == 4) dir = 0;
way[index].push_back(dir);
map[startp[index].x][startp[index].y] = 1;
int movei = startp[index].x + mv[dir].x;
int movej = startp[index].y + mv[dir].y;
startp[index] = { movei,movej,-1,startp[index].g };
}
map[startp[index].x][startp[index].y] = 1;
}
}
void printmap() {
cout << endl;
for (int i = 0; i <= 15; i++) {
for (int j = 0; j <= 15; j++) {
cout << map[i][j]<< " ";
}
cout << endl;
}
cout << endl;
}
int main(void) {
cin >> n;
memset(map, 0, sizeof(map));
startp.resize(n);
way.resize(n);
for (int i = 0; i < n; i++) {
int x, y, d, g;
cin >> x >> y >> d >> g;
startp[i] = { y,x,d,g };
MoveDragon(i);
}
int j = 0;
int i = 0;
for (int i = 0; i < 100; i++) {
int j = 0;
int ii = i;
while (j < 100) {
int count = 0;
if (map[ii][j] == 1) count++;
if (map[ii][j + 1] == 1) count++;
if (map[ii + 1][j] == 1) count++;
if (map[ii + 1][j + 1] == 1) count++;
if (count == 4) {
answer++;
}
j++;
}
}
cout << answer << endl;
}