[백준 8718] Bałwanek (C#, C++) - soo:bak
작성일 :
문제 링크
설명
주어진 눈의 양으로 만들 수 있는 최대 눈사람 부피를 구하는 문제입니다.
접근법
눈사람의 세 눈덩이는 4:2:1 비율이어야 합니다.
주어진 눈덩이 k를 맨 위, 중간, 맨 아래에 배치하는 세 경우를 고려합니다.
각 경우 필요한 총 부피는 7k, 3.5k, 1.75k이고, 밀리리터로 환산하면 7000k, 3500k, 1750k입니다.
큰 눈사람부터 시도하여 가능한 최대 부피를 출력합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
class Program {
static void Main() {
var line = Console.ReadLine()!.Split();
var x = int.Parse(line[0]);
var k = int.Parse(line[1]);
var totalMl = x * 1000;
var ans = 0L;
if (7000 * k <= totalMl) ans = 7000 * k;
else if (3500 * k <= totalMl) ans = 3500 * k;
else if (1750 * k <= totalMl) ans = 1750 * k;
Console.WriteLine(ans);
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x, k; cin >> x >> k;
int total = x * 1000;
int ans = 0;
if (7000 * k <= total) ans = 7000 * k;
else if (3500 * k <= total) ans = 3500 * k;
else if (1750 * k <= total) ans = 1750 * k;
cout << ans << "\n";
return 0;
}