알고리즘
백준 18111번 문제 ( 마인크래프트 )
뀨심볼
2020. 2. 1. 18:30
문제 출처 : https://www.acmicpc.net/problem/18111
18111번: 마인크래프트
팀 레드시프트는 대회 준비를 하다가 지루해져서 샌드박스 게임인 ‘마인크래프트’를 켰다. 마인크래프트는 1 × 1 × 1(세로, 가로, 높이) 크기의 블록들로 이루어진 3차원 세계에서 자유롭게 땅을 파거나 집을 지을 수 있는 게임이다. 목재를 충분히 모은 lvalue는 집을 짓기로 하였다. 하지만 고르지 않은 땅에는 집을 지을 수 없기 때문에 땅의 높이를 모두 동일하게 만드는 ‘땅 고르기’ 작업을 해야 한다. lvalue는 세로 N, 가로 M 크기의 집터를
www.acmicpc.net
이 문제는 땅의 높이를 일정하게 바꾸어서 최소 시간과 땅의 높이를 출력하는 것이다.
최소 높이와 최대 높이를 찾아서 브루트 포스를 이용하여 해결 할 수 있었다.
아래는 이 문제를 해결한 소스이다.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include<stdio.h>
#pragma warning(disable:4996)
int arr[501][501];
int main()
{
int N;
int M;
int B;
int max=-1;
int min=501;
int time_result = 99999999;
int block_height = 99999999;
scanf("%d %d %d", &N, &M, &B);
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
scanf("%d", &arr[i][j]);
if (min > arr[i][j])
min = arr[i][j];
if (max < arr[i][j])
max = arr[i][j];
}
}
for (int i = min; i <= max; i++)
{
int time = 0;
int block = B;
for (int j = 0; j < N; j++)
{
for (int k = 0; k < M; k++)
{
int height = arr[j][k]-i;
if (height > 0)
{
time = time + height * 2;
block = block + height;
}
else if (height < 0)
{
time = time - height;
block = block + height;
}
}
}
if (block >=0)
{
if (time <= time_result)
{
time_result = time;
block_height = i;
}
}
}
printf("%d %d", time_result, block_height);
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|