문제 링크입니다: www.acmicpc.net/problem/16785
16785번: ソーシャルゲーム
JOI 君が少なくとも C 枚のコインを得るためにログインしなければならない回数の最小値を出力せよ.
www.acmicpc.net
int형 변수에 대해 형변환을 진행한 뒤 나누기 연산을 진행해야하는 문제였습니다.
알고리즘은 아래와 같습니다.
1. 일주일에 얻을 수 있는 점수를 temp 변수에 저장합니다.
2. 최대한 temp를 채워넣고(C / temp) 남은 점수에 대해 연산을 진행해야하는데 해당 수식은 아래와 같습니다.
i) 필요한 날이 k라 하면 k * A > C % temp를 만족하는 k를 찾아야합니다.
ii) 7일차에 보너스 점수를 받으므로 최대 7일이 걸립니다.
iii) 따라서 min(k, 7) 결과를 C / temp에 더해주면 답을 구할 수 있습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <algorithm> | |
using namespace std; | |
const int WEEK = 7; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int A, B, C; | |
cin >> A >> B >> C; | |
int weeklyScore = WEEK * A + B; | |
int result = C / weeklyScore * WEEK + min((int)ceil((double)(C % weeklyScore) / (double)A), WEEK); | |
cout << result << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 17362번 수학은 체육과목 입니다 2 (0) | 2021.03.26 |
---|---|
백준 17009번 Winning Score (0) | 2021.03.26 |
백준 16727번 ICPC (0) | 2021.03.26 |
백준 16693번 Pizza Deal (0) | 2021.03.25 |
백준 16648번 Accumulator Battery (0) | 2021.03.24 |