Think by the difference between max and min
answerA.py
x=[int(input()) for i in range(5)]
k=int(input())
print("Yay!" if max(x)-min(x)<=k else ":(")
If the cooking time is only a multiple of 10, it doesn't matter in any order. If the cooking time is not a multiple of 10, ask for the one that is not a multiple of 10 and has the smallest remainder after dividing by 10. You can get the last dish delivered sooner.
answerB.py
import math
x=[int(input()) for i in range(5)]
y=[i%10 for i in x]
ans=0
for i in range(5):
ans+=math.ceil(x[i]/10)*10
check=10
for i in range(5):
if y[i]!=0:
check=min(check,y[i])
if check==10:
print(ans)
else:
print(ans-(10-check))
I feel like it's the third time I've solved it ...
It's easy because I know the answer once, but isn't it quite difficult at first glance?
Obviously, the straightforward simulation shows that it is not in time, so if you experiment appropriately, you can see that the place where the number of people who can pass at one time is the smallest becomes a bottleneck and there is a blockage **. In addition, clogging other than the bottleneck can be combined into clogging at the bottleneck. In other words, you can ignore clogging in other parts by assuming that the bottleneck causes clogging by `math.ceil (n / min (x))-1```. If there is no bottleneck, it will arrive in 5 minutes in the shortest time, so the answer you are looking for is
`5 + math.ceil (n / min (x))-1```.
answerC.py
import math
n=int(input())
x=[int(input()) for i in range(5)]
print(5+math.ceil(n/min(x))-1)
I didn't even know what went wrong in the RE and TLE on-parade. At first, I tried to solve with Writer solution 3 and stopped thinking of a simple implementation, and then tried to solve with 4 and the bug fix was quite good. I didn't go. This (Python ver, C ++ ver) is my ( It will be the answer (incorrect answer). I think that the pattern of repeated strays like this is due to ** I haven't been able to clarify what I want to do **. When I'm straying, I think I should reconsider with an awareness of ** clarifying the policy ** (but it's difficult because I'm impatient during the contest ...).
After a lot of consideration, I was finally able to AC in a way that I was satisfied with. There seem to be several solutions, but I will introduce two of them in Separate article.
Recommended Posts