From this time, I'm planning to solve the problem of competitive professionals (AtCoder) with python3 every day. The problem selection is from Recommendations in AtCoder Problems (https://kenkoooo.com/atcoder/#/list/tax_free).
--Increase the rate. ――Getting the ability to respond to first-time problems
#1 Problem
** Thoughts ** 2WA. I found that I was not good at the problem of thinking about case classification. This issue was categorized by the size of n mod (10). If you read the question, you will be asked how much it will cost to buy N or more, so you will know that you can buy more than N. The following is a comparison of whether it is cheaper to buy individually or collectively with n mod (10).
n mod(10),Individual,Individualとまとめて買ったときの差
1 , 15 , 85
2 , 30 , 70
3 , 45 , 55
4 , 60 , 40
5 , 75 , 25
6 , 90 , 10
7 , 105 , -5
8 , 120 , -20
9 , 135 , -35
10 , 150 , -50
It will be. From this, you can see that it is cheaper to buy in bulk when n mod (10)> 6. Therefore,
if n % 10 > 6:
b = 100 * (n // 10 + 1)
else:
p = n % 10
b = 100 * (n // 10) + p * 15
If you set it to, you can meet the conditions well. All you have to do is add standard inputs and outputs to the code above. Use min () for output.
n = int(input())
a = 15 * n
if n % 10 > 6:
b = 100 * (n // 10 + 1)
else:
p = n % 10
b = 100 * (n // 10) + p * 15
print(min(a,b))
It is regrettable that 2WA was issued even though it was a problem. There is a disturbing word in the tag, but I will do my best not to do so.
Recommended Posts