Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Redmine theme
- Node
- 배열컬럼
- 레드마인 테마
- rpm목록
- 레드마인
- pg환경변수
- 멀티 인스턴스
- tomcat install
- node postgresql
- 리액트네이티브
- multi instance
- nodejs 환경변수처리
- sqlmap 경고
- redmine
- intelij sqlmap
- .env
- intelij mybatis
- 패키지
- Java
- 메소드한줄
- 배열크기
- yum목록
- 레드마인테마
- sqlmap warring
- CentOS
- yum설치목록
- dotenv
- node.js postgresql
- rpm설치목록
Archives
- Today
- Total
ZeroRadish
[백준] 3019번 테트리스(JAVA) 본문
https://www.acmicpc.net/problem/3019
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
int C = Integer.parseInt(tokenizer.nextToken());
int P = Integer.parseInt(tokenizer.nextToken());
int[] heights = new int[C];
tokenizer = new StringTokenizer(reader.readLine());
for (int i = 0; i < C; i++) {
heights[i] = Integer.parseInt(tokenizer.nextToken());
}
int count = countMatchingBlocks(heights, P);
writer.write(count + "\n");
reader.close();
writer.flush();
writer.close();
}
private static int countMatchingBlocks(int[] heights, int blockType) {
List<int[]> blocks = getBlocks(blockType);
int count = 0;
for (int[] block : blocks) {
for (int i = 0; i <= heights.length - block.length; i++) {
if (matches(heights, i, block)) {
count++;
}
}
}
return count;
}
private static List<int[]> getBlocks(int blockType) {
List<int[]> blocks = new ArrayList<>();
switch (blockType) {
case 1:
blocks.add(new int[]{0});
blocks.add(new int[]{0, 0, 0, 0});
break;
case 2:
blocks.add(new int[]{0, 0});
break;
case 3:
blocks.add(new int[]{0, 0, 1});
blocks.add(new int[]{1, 0});
break;
case 4:
blocks.add(new int[]{1, 0, 0});
blocks.add(new int[]{0, 1});
break;
case 5:
blocks.add(new int[]{0, 0, 0});
blocks.add(new int[]{1, 0});
blocks.add(new int[]{0, 1});
blocks.add(new int[]{1, 0, 1});
break;
case 6:
blocks.add(new int[]{0, 0, 0});
blocks.add(new int[]{0, 0});
blocks.add(new int[]{0, 1, 1});
blocks.add(new int[]{2, 0});
break;
case 7:
blocks.add(new int[]{0, 0, 0});
blocks.add(new int[]{0, 2});
blocks.add(new int[]{1, 1, 0});
blocks.add(new int[]{0, 0});
break;
}
return blocks;
}
private static boolean matches(int[] heights, int startIndex, int[] block) {
int minHeight = Integer.MAX_VALUE;
for (int j = 0; j < block.length; j++) {
minHeight = Math.min(minHeight, heights[startIndex + j]);
}
for (int j = 0; j < block.length; j++) {
if (heights[startIndex + j] - minHeight != block[j]) {
return false;
}
}
return true;
}
}
Comments