반응형

백준 19698번 헛간 청약 풀이 코드

C | C++ | Java | Python


풀이

가로, 세로를 각각 L로 나눈 후 곱하면 방의 개수가 나옵니다. 방보다 소들이 적다면 최대 입주수는 소들의 수와 같습니다.

코드

#include <stdio.h>
int main() {
    int n, w, h, l;
    scanf("%d %d %d %d", &n, &w, &h, &l);
    int ans = (w / l) * (h / l);
    printf("%d", n < ans ? n : ans);
    return 0;
}
#include <iostream>
using namespace std;
int main() {
    int n, w, h, l;
    cin >> n >> w >> h >> l;
    int ans = (w / l) * (h / l);
    n < ans ? cout << n : cout << ans;
    return 0;
}
import java.util.Scanner;
import java.lang.Math;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), w=sc.nextInt(), h=sc.nextInt(), l=sc.nextInt();
        int ans = (w / l) * (h / l);
        System.out.println(Math.min(n, ans));
    }
}
n, w, h, l = map(int, input().split())
ans = (w // l) * (h // l)
if n < ans:
    print(n)
else:
    print(ans)

문제 출처

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

반응형

+ Recent posts