반응형

백준 13136번 Do Not Touch Anything 풀이 코드

C | C++ | Java | Python


풀이

가로 세로를 각각 커버리지로 나눈 후 그 수를 곱하면 필요한 CCTV 수를 알 수 있습니다. 이때 정확히 나누어 떨어지지 않으면 어쩔 수 없이 CCTV가 한 줄 더 필요하므로 조건문을 추가합니다. 곱한 값이 int 범위를 넘어갈 수 있으므로 C, C++, Java에선 변수형에 유의해 주세요.

코드

#include <stdio.h>

int main(){
    long long r, c, n, x, y;
    scanf("%lld %lld %lld", &r, &c, &n);
    if (r%n)
        x = r/n + 1;
    else
        x = r/n;
    if (c%n)
        y = c/n + 1;
    else
        y = c/n;
    printf("%lld", x*y);
    return 0;
}
#include <iostream>
using namespace std;

int main(){
    long long r, c, n, x, y;
    cin>>r>>c>>n;
    if (r%n)
        x = r/n + 1;
    else
        x = r/n;
    if (c%n)
        y = c/n + 1;
    else
        y = c/n;
    cout<<x*y;
    return 0;
}
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt(), c = sc.nextInt(), n = sc.nextInt();
        long x, y;
        if (r%n > 0)
            x = r/n + 1;
        else
            x = r/n;
        if (c%n > 0)
            y = c/n + 1;
        else
            y = c/n;
        System.out.println(x*y);
    }
}
r, c, n = map(int, input().split())
if r%n:
    x = r//n + 1
else:
    x = r//n
if c%n:
    y = c//n + 1
else:
    y = c//n
print(x*y)

문제 출처

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

반응형

+ Recent posts