on
백준 11559 - Puyo Puyo
백준 11559 - Puyo Puyo
https://www.acmicpc.net/problem/11559
★ 풀이
★ 소스 코드
import java.io.*; import java.util.*; // 좋은 스킬 흡수하기 public class Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); static char board[][]; static boolean visited[][]; static boolean isChanged; static int dx[] = {0,1,0,-1}; static int dy[] = {1,0,-1,0}; static int n = 12,m = 6; public static void main(String[] args) throws IOException { board = new char[12][6]; for(int i = 0; i<12; i++) { board[i] = br.readLine().toCharArray(); } int ans = 0; isChanged = true; while(isChanged) { isChanged = false; searchDelBlocks(); gravity(); if(isChanged) ans++; } System.out.println(ans); } static void searchDelBlocks() { visited = new boolean[12][6]; for(int i = 0; i q = new LinkedList(); q.add(new Point(x,y)); visited[x][y] = true; List blocksToDel = new LinkedList(); blocksToDel.add(new Point(x,y)); while(!q.isEmpty()) { Point now = q.poll(); for(int i= 0; i<4; i++) { int nx = now.x + dx[i]; int ny = now.y + dy[i]; if(isInBoard(nx,ny) && color == board[nx][ny] && !visited[nx][ny]) { visited[nx][ny] = true; blocksToDel.add(new Point(nx,ny)); q.add(new Point(nx,ny)); } } } if(blocksToDel.size() >= 4) { isChanged = true; for(Point block : blocksToDel) { board[block.x][block.y] = '.'; } } } static boolean isInBoard(int x, int y) { if(x < n && x >= 0 && y < m && y >= 0) { return true; } return false; } static void gravity() { for(int c = 0; c0; r--) { if(board[r][c] == '.') { for(int k = r - 1; k>=0; k--) { if(board[k][c] != '.') { board[r][c] = board[k][c]; board[k][c] = '.'; break; } } } } } } } class Point{ int x,y; Point(int x, int y){ this.x = x; this.y = y; } }
from http://sweet-smell.tistory.com/148 by ccl(A) rewrite - 2021-12-09 04:28:08