반응형
https://www.acmicpc.net/problem/9664
9664번: NASLJEDSTVO
Clarification of the first example: There are two daughters, so that means the youngest daughter took half of the medallions. If there were initially 9 medallions, the youngest took 4, so 5 are remaining. If, by any chance, there were initially 10 medallio
www.acmicpc.net
간단 구현 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
전체 딸의 명 수 daughter, 남은 medal, 한명의 딸이 가져갈 medal 수, 막내를 제외한 딸들이 명당 가져간 최소 medal 수 di, 최소 정답 minAns를 선언 후 적절히 입력받습니다.
📔 풀이과정
di = 현재 남은 medal 수 / (전체 딸의 수 - 1명(막내)) 가 됩니다.
예제 1에서 딸이 2명 남은 medal이 5개이므로 di는 5가 됩니다
남은 메달 - 나머지 딸들이 가져간 medal 수가 0이라면 전체 medal에서 1개를 빼고 막내가 di-1만큼 가져가면 되니 최소는 remainMedal + di - 1이 되며 최대는 remainMedal + di가 됩니다.
아닌 경우는 최소 최대가 같습니다.
📔 정답출력
조건에 맞게 정답을 출력합니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
int daughter, remainMedal, di, minAns;
int main(){
cin >> daughter >> remainMedal;
di = remainMedal / (daughter-1);
minAns = remainMedal + di;
if(remainMedal - di * (daughter-1) == 0) cout << minAns - 1 << ' ' << minAns << '\n';
else cout << minAns << ' ' << minAns;
}
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - 백준(BOJ) 18698 : The Walking Adam (0) | 2022.08.05 |
---|---|
(C++) - 백준(BOJ) 8806 : Papier kamień nożyczki (0) | 2022.08.03 |
(Python3) - 백준(BOJ) 14782 : Bedtime Reading, I (0) | 2022.08.01 |
(C++) - 백준(BOJ) 25285 : 심준의 병역판정검사 (0) | 2022.07.31 |
(C++) - 백준(BOJ) 4696 : St. lves (0) | 2022.07.29 |