Past questions solved for the first time
When I wrote it with the ternary operator, the number of characters was small, so I could type it quickly.
answerA.py
a,b=map(int,input().split())
print(a+b if a+b<10 else "error")
Whether or not there is a cover is set, the ternary operator is also used here
answerB.py
s=list(input())
t=list(set(s))
print("yes" if len(s)==len(t) else "no")
Cases are divided according to whether they are multiples of 10, and when there are only multiples of 10, the sum is always a multiple of 10, so 0 is output. If there are things that are not multiples of 10, add them all up and if they are multiples of 10, then they are not multiples of 10. All you have to do is pull the smallest one.
answerC.py
n=int(input())
a=[]
b=[]
for i in range(n):
s=int(input())
if s%10==0:
a.append(s)
else:
b.append(s)
b.sort()
if len(b)==0:
print(0)
else:
if sum(b)%10==0:
print(sum(a)+sum(b[1:]))
else:
print(sum(a)+sum(b))
The B problem of the latest AGC041 was a fairly similar problem (typical ??). First of all, ** it is inevitable that repeating the explosion honestly will not be in time for the calculation amount **, so I thought about what would happen if the explosion was repeated $ X $ times. Now, for $ X $ explosions, suppose there are $ m_i $ explosions centered around the $ i $ th monster. At this time, the physical strength of the $ i $ th monster is $ h_i-m_i \ times A- (X-m_i) \ times B = h_i-X \ times B-m_i \ times (AB) $, which is an arbitrary 1 If <= $ i $ <= N is 0 or less, you can defeat all N monsters. Therefore, ** $ (h_i-X \ times B) / (A-B) $ rounded up is the number of explosions around that monster required to defeat each monster **. If this number of times is calculated for each monster and the added value is $ X $ or less, it can be said that all monsters can be erased by x explosions. Also, it is clear from the constraint that ** $ X $ is at most $ 10 ^ 9 $, and it is clear that all monsters can be erased at the boundary of $ X $ **, so the value is calculated by binary search. You can ask for it. From the above, it was found that it can be calculated by a constant multiple (about 10 times) of O (n).
answerD.py
import math
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
def explode(x):
global n
c=0
for i in range(n):
if h[i]-x*b>0:
c+=math.ceil((h[i]-x*b)/(a-b))
return c<=x
l,r=1,10**9
while l+1<r:
k=(l+r)//2
if explode(k):
r=k
else:
l=k
print(l if explode(l) else r)
Recommended Posts