본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 18301번 : Rats 답

반응형

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

 

18301번: Rats

To celebrate the Lunar New Year of the Rat, Douglas decides to count the number of rats living in his area. It is impossible for him to find all rats, as they tend to be well hidden. However, on the first day of the new year, Douglas manages to capture n1

www.acmicpc.net

단순구현 문제였습니다.

floor함수를 써서 내림한 결과값을 반환받고 출력하였습니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
double n1, n2, n12, ans;
//n := ⌊(n1 + 1)(n2 + 1)/(n12 + 1) - 1⌋
void input() {
    cin >> n1 >> n2 >> n12;
}
void sol() {
    input();
    ans = ((n1 + 1)*(n2 + 1/ (n12 + 1)) - 1;
    cout << floor(ans);//내림하는 함수입니다.
}
int main() {
    sol();
}
cs