티스토리 뷰
https://www.acmicpc.net/problem/15685
드래곤 커브가 세대를 거듭할수록 이전 세대의 드래곤 커브에서 왼쪽으로 90도 회전한 것이 추가된다. 이 때 규칙을 발견할 수 있다. 처음 시작점부터의 방향을 저장해 나간다. 다음 세대의 드래곤 커브는 지금까지 저장한 방향을 역순으로 보면서 방향 전환하고 왼쪽으로 90도 회전한 방향을 추가하면 된다. 모든 드래곤 커브를 맵에 표시한 후 맵 전체를 살펴본다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <cstdio> #include <vector> using namespace std; int n,x,y,d,g,s,map[105][105],ans; int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0}; int change(int d) { // 방향 전환 if(d==0 || d==1) d+=2; else d-=2; // 왼쪽으로 90도 회전 if(d==0) d=3; else d--; return d; } int main() { scanf("%d",&n); while(n--) { scanf("%d %d %d %d",&y,&x,&d,&g); vector<int> v; v.push_back(d); while(g--) { s=v.size(); for(int i=s-1;i>=0;i--) v.push_back(change(v[i])); } map[x][y]=1; s=v.size(); for(int i=0;i<s;i++) { x+=dx[v[i]],y+=dy[v[i]]; map[x][y]=1; } } for(int i=0;i<100;i++) for(int j=0;j<100;j++) if(map[i][j] && map[i+1][j] && map[i][j+1] && map[i+1][j+1]) ans++; printf("%d\n",ans); return 0; } | cs |
'Algorithm > BOJ' 카테고리의 다른 글
15649 N과 M (1) (0) | 2018.06.06 |
---|---|
3067 Coins (0) | 2018.05.19 |
15686 치킨 배달 (0) | 2018.04.16 |
14891 톱니바퀴 (0) | 2018.04.09 |
14890 경사로 (0) | 2018.04.09 |