Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
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
Archives
Today
Total
관리 메뉴

Life Engineering

[BOJ 18111] 마인크래프트 (Java) 본문

Problem Solving

[BOJ 18111] 마인크래프트 (Java)

흑개 2022. 3. 22. 00:19

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

 

18111번: 마인크래프트

팀 레드시프트는 대회 준비를 하다가 지루해져서 샌드박스 게임인 ‘마인크래프트’를 켰다. 마인크래프트는 1 × 1 × 1(세로, 가로, 높이) 크기의 블록들로 이루어진 3차원 세계에서 자유롭게

www.acmicpc.net

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

public class Main_BOJ_18111 {
	static int N, M, B;
	static int[][] map;
	static int min=Integer.MAX_VALUE;
	static int answer_height;
	static int answer_time=Integer.MAX_VALUE;
	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		N=Integer.parseInt(st.nextToken());
		M=Integer.parseInt(st.nextToken());
		B=Integer.parseInt(st.nextToken());
		map=new int[N][M];
		for (int i=0; i<N; i++) {
			st=new StringTokenizer(br.readLine());
			for (int j=0; j<M; j++) {
				map[i][j]=Integer.parseInt(st.nextToken());
				if (min>map[i][j]) min=map[i][j];
			}
		}
		for (int t=0; t<=256; t++) {
			play(t);
		}
		System.out.println(answer_time+" "+answer_height);

	}
	private static void play(int t) {
		int sum=0;
		int block=0;
		int toLoad=0;
		for (int i=0; i<N; i++) {
			for (int j=0; j<M; j++) {
				if (map[i][j]>t) {		//크다면 제거  
					sum+=(map[i][j]-t)*2;
					block+=(map[i][j]-t);
				}
				else if (map[i][j]<t) {	//작다면 넣어주기
					toLoad+=(t-map[i][j]);
				}
			}
		}
		if (B+block<toLoad) return;
		else {
			sum+=(toLoad);
		}
		if (answer_time>=sum) {	//최대한 큰 높이
			answer_time=sum;
			answer_height=t;
		}
	}

}

문제의 조건을 정확히 읽는게 중요했던 문제.

 

'Problem Solving' 카테고리의 다른 글

[BOJ 1918] 후위 표기식 (Java)  (0) 2022.03.22
[BOJ 1967] 트리의 지름 (Java)  (0) 2022.03.22
[BOJ 16928] 뱀과 사다리 게임 (Java)  (0) 2022.03.20
[BOJ 2565] 전깃줄 (Java)  (0) 2022.03.17
[BOJ 2638] 치즈 (Java)  (0) 2022.03.17