알고리즘/BOJ

[BJ]15685 드래곤 커브

  • -
반응형

BJ G4 15685 드래곤 커브

 

문제링크

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

 

15685번: 드래곤 커브

첫째 줄에 드래곤 커브의 개수 N(1 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에는 드래곤 커브의 정보가 주어진다. 드래곤 커브의 정보는 네 정수 x, y, d, g로 이루어져 있다. x와 y는 드래곤 커

www.acmicpc.net

* 일단 문제를 정독 하고 1시간 이상 반드시 고민이 필요합니다.

 

 

동영상 설명

1시간 이상 고민 했지만 아이디어가 떠오르지 않는다면 동영상에서 약간의 힌트를 얻어봅시다.

 

소스보기

동영상 설명을 보고도 전혀 구현이 안된다면 연습 부족입니다.
소스를 보고 작성해 본 후 스스로 백지 상태에서 3번 작성해 볼 의지가 있다면 소스를 살짝 보세요.

더보기
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
 * @author 은서파
 * @since 2021. 11. 15.
 * @see https://www.acmicpc.net/problem/15685
 * @performance 12124	84
 * @category #시뮬레이션, #규
 * @memo
 */

public class BJ_G4_15685_드래곤커브 {

	static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
	static StringBuilder output = new StringBuilder();
	static StringTokenizer tokens;

	static int N;
	// 커브의 방향 매핑 : 인덱스를 기존 방향으로, 값을 새롭게 대체될 방향으로
	static int [] curveMap = {1, 2, 3, 0};
	static int [][] deltas = {{0, 1},{-1, 0},{0, -1},{1, 0}};
	static boolean [][] map = new boolean[101][101];
	
	public static void main(String[] args) throws IOException {
		input = new BufferedReader(new StringReader(src));
		N = Integer.parseInt(input.readLine());
		for(int n=0; n<N; n++) {
			tokens = new StringTokenizer(input.readLine());
			int x = Integer.parseInt(tokens.nextToken());
			int y = Integer.parseInt(tokens.nextToken());
			int d = Integer.parseInt(tokens.nextToken());
			int g = Integer.parseInt(tokens.nextToken());
			
			makeCurve(x, y, d, g);
		}
		// 입력 완료
		// 커브 작성 완료
		int cnt = 0;
		for(int r=0; r<100; r++) {
			for(int c=0; c<100; c++) {
				if(map[r][c] && map[r+1][c] && map[r][c+1] && map[r+1][c+1]) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
	
	private static void makeCurve(int x, int y, int d, int g) {
		// 출발점
		map[y][x]=true;
		// 0세대의 끝점
		int endR = y + deltas[d][0];
		int endC = x + deltas[d][1];
		int endD = curveMap[d];
		// 0세대 작성 끝!!!
		
		List<Point> points = new ArrayList();
		points.add(new Point(endR, endC, endD));
		
		
		for(int i=0; i<g; i++) {
			// 리스트에 담긴 것의 역 순으로 소진시켜주기
			for(int j=points.size()-1; j>=0; j--) {
				Point last = points.get(j);
				// 기존의 마지막 점에서 계속 그려나가기
				endR+=deltas[last.d][0];
				endC+=deltas[last.d][1];
				endD = curveMap[last.d];
				points.add(new Point(endR, endC, endD));
			}
		}
		
	}

	static class Point{
		int r, c, d;
		
		public Point(int r, int c, int d) {
			this.r = r;
			this.c= c;
			this.d = d;
			// 생성되면 지도에 표시된다.!!
			map[r][c] = true;
		}
	}

	// REMOVE_START
	private static String src = "4\r\n"
								+ "50 50 0 10\r\n"
								+ "50 50 1 10\r\n"
								+ "50 50 2 10\r\n"
								+ "50 50 3 10";
	// REMOVE_END

}

 

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

[BJ]G5 16234 인구이동  (0) 2021.11.30
[BJ]P5 5373 큐빙  (0) 2021.11.25
[BJ]15684 사다리조작  (0) 2021.11.07
[BJ]G3 14890 경사로  (0) 2021.11.03
[BJ]14889. 스타트와링크  (0) 2021.11.02
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.