티스토리 뷰

Algorithm

[백준] S2 3019 테트리스 (java)

코딩브론즈 2020. 12. 28. 16:18

www.acmicpc.net/problem/3019

 

3019번: 테트리스

테트리스는 C열 필드위에서 플레이하는 유명한 게임이다. 필드의 행의 수는 무한하다. 한 번 움직일 때, 아래와 같은 일곱가지 블록 중 하나를 필드에 떨어뜨릴 수 있다. 블록을 떨어뜨리기 전에

www.acmicpc.net

 

풀이

 

0) 1번 부터 7번까지 모든 경우를 다 따질거임. answer 변수 생성하여 조건 맞을때마다 +1 함.

1-1) |  : answer += C

1-2) ㅡ : map[i] = map[i+1] = map[i+2] = map[i+3]

2) ㅁ : map[i] = map[i+1]

3) 번개모양.. : 세울때와 눕힐때 따로 구해서 answer에 +

4) 번개모양2 : 3과 동일. 특수 문자가 없다..

5-1) ㅗ : map[i] = map[i+1] = map[i+2]

5-2) ㅓ : map[i] = map[i+1] +1

5-3) ㅏ : map[i] = map[i+1] -1

5-4) ㅜ : map[i] = map[i+1] +1 = map[i+2]

6-1) ┛ : 5-1

6-2) └ : 2

6-3) ┌ : map[i] = map[i+1] - 1 = map[i+2] - 1

6-4) ┐ : map[i] = map[i+1] +2

7-1) └ : 5-1

7-2) ┌ : map[i] = map[i+1] -2

7-3) ┐: map[i] = map[i+1] = map[i+2] + 1

7-1) ┘ : 2

 

주의사항

 

1) 노가다

 

package com.baekJoon;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.StringTokenizer;

public class BJ_S1_3019_테트리스 {
	static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer tokens;
	static int C, P, map[], answer;
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		input = new BufferedReader(new StringReader(src));
		tokens = new StringTokenizer(input.readLine());
		C = Integer.parseInt(tokens.nextToken());
		P = Integer.parseInt(tokens.nextToken());
		map = new int[C];
		tokens = new StringTokenizer(input.readLine());
		
		for(int c=0; c<C; c++) {
			map[c] = Integer.parseInt(tokens.nextToken());
		}
		solve();
		System.out.println(answer);
	}

	private static void solve() {
		switch (P) {
		case 1:
			answer += C;
			for(int c=0; c<C-3; c++) {
				if(map[c]== map[c+1] && map[c]== map[c+2] && map[c]== map[c+3]) {
					answer++;
				}
			}
			break;
		case 2:
			for(int c=0; c<C-1; c++) {
				if(map[c]== map[c+1]) {
					answer++;
				}
			}
			break;
		case 3:
			for(int c=0; c<C-2; c++) {
				if(map[c] == map[c+1] && map[c+2] == map[c]+1) {
					answer++;
				}
			}
			for(int c=0; c<C-1; c++) {
				if(map[c] == map[c+1]+1) {
					answer++;
				}
			}
			break;
		case 4:
			for(int c=0; c<C-2; c++) {
				if(map[c] == map[c+1]+1 && map[c] == map[c+2]+1) {
					answer++;
				}
			}
			for(int c=0; c<C-1; c++) {
				if(map[c] == map[c+1]-1) {
					answer++;
				}
			}
			break;
		case 5:
			for(int c=0; c<C-2; c++) {
				if(map[c]== map[c+1] && map[c]== map[c+2]) {
					answer++;
				}
			}
			for(int c=0; c<C-1; c++) {
				if(map[c] == map[c+1]+1) {
					answer++;
				}
			}
			for(int c=0; c<C-1; c++) {
				if(map[c] == map[c+1]-1) {
					answer++;
				}
			}
			for(int c=0; c<C-2; c++) {
				if(map[c]== map[c+1]+1 && map[c]== map[c+2]) {
					answer++;
				}
			}
			break;
		case 6:
			for(int c=0; c<C-2; c++) {
				if(map[c]== map[c+1] && map[c]== map[c+2]) {
					answer++;
				}
			}
			for(int c=0; c<C-1; c++) {
				if(map[c]== map[c+1]) {
					answer++;
				}
			}
			for(int c=0; c<C-2; c++) {
				if(map[c]== map[c+1]-1 && map[c]== map[c+2]-1) {
					answer++;
				}
			}
			for(int c=0; c<C-1; c++) {
				if(map[c]== map[c+1]+2) {
					answer++;
				}
			}
			break;
		case 7:
			for(int c=0; c<C-2; c++) {
				if(map[c]== map[c+1] && map[c]== map[c+2]) {
					answer++;
				}
			}
			for(int c=0; c<C-1; c++) {
				if(map[c]== map[c+1]) {
					answer++;
				}
			}
			for(int c=0; c<C-2; c++) {
				if(map[c]== map[c+1] && map[c]== map[c+2]+1) {
					answer++;
				}
			}
			for(int c=0; c<C-1; c++) {
				if(map[c]== map[c+1]-2) {
					answer++;
				}
			}
			break;
		}
	}

	static String src =
			"6 6\r\n" + 
			"3 1 1 1 1 1";
}

 

 

후기

 

노가다 끝판왕 문제. 너무 귀찮았다...

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함