https://codeforces.com/contest/1296/problem/B
목적
초기에 s만큼의 금액이 주어지고, 사용한 금액의 10%(소수점 이하 무시)를 돌려받을 때, 최대로 사용할 수 있는 금액을 구하자.
접근법
1. cashback을 최대로 만들 수 있게 금액을 사용하면 된다.
2. 10으로 나눈 나머지는 돌려받지 못하고 몫만 돌려받으므로, 10의 배수의 금액만 사용하여 불필요한 지출을 줄이자.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include<bits/stdc++.h>
#define f(i,l,r) for(int i=l;i<r;++i)
using namespace std;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) {
int s; cin >> s;
int ans = 0;
while (s >= 10) {
int tmp = (s / 10) * 10;
ans += tmp;
s = s - tmp + tmp / 10;
}
cout << ans + s << '\n';
}
return 0;
}
|
문제 설명과 코드에 대한 피드백은 언제나 환영합니다.
다양한 의견 댓글로 남겨주세요.
'Problem Solving > Codeforces' 카테고리의 다른 글
[ Codeforces 1296A - Array with Odd Sum ] 해설 및 코드 (0) | 2020.02.20 |
---|