It's a simple time, but I felt that the D problem was a basic and good problem. This time, I used AtCoder Virtual Contest.
Replace with 8. Since the string is immutable, I think it's either split once (first) or changed to a list and replaced (second).
answerA1.py
s=input()
print(s[:3]+"8"+s[4:])
answerA2.py
s=list(input())
s[3]="8"
print("".join(s))
It is not possible to use rice cakes of the same diameter, so you should consider excluding duplicates. You can use set for that.
answerB.py
n=int(input())
d=[int(input()) for i in range(n)]
print(len(set(d)))
Since y is a multiple of 1000, you can divide it by 1000 and think about the equation 10i + 5j + k = y (0 <= i, j, k <= n, i + j + k = n). Such inequalities should be decided from the place where the coefficient is large, and in this problem, it is decided in the order of i → j → k. 0 ~ y // 10 is a candidate for i, 0 ~ (y-i * 10) // 5 is a candidate for j, and k is determined. By trying the above for all i and j, you can find an answer that meets your needs.
answerC.py
from sys import exit
n,y=map(int,input().split())
y//=1000
for i in range(y//10+1):
#k: How much is left
#l: How many sheets were used
k1=y-i*10
for j in range(k1//5+1):
k=k1-j*5
l=i+j
if k==n-l and i>=0 and j>=0 and k>=0:
print(str(i)+" "+str(j)+" "+str(k))
exit()
print("-1 -1 -1")
If you can decide which sword to swing and how many times to throw before defeating the monster, you can decide regardless of the order. First of all, regarding how many times to swing which sword, since each sword can be swung multiple times and the sword with the higher point should be swung, only the sword with the highest point ** ** (point $ a_k $) It is best to keep shaking. Next, regarding which sword to throw, it is not necessary to throw a sword whose point (when thrown) is lower than the point $ a_k $ (the point is better to swing the sword with point $ a_k $ instead. Because it is expensive). Therefore, throwing swords are all swords with higher points (when thrown) than point $ a_k $. From the above consideration, first, assuming that all swords with higher points (when thrown) than point $ a_k $ are thrown, draw in order from H point, and even if it is assumed that all of them are thrown, H to the monster If you can't do more damage than points, you can swing the sword with points $ a_k $ as much as you need.
answerD.py
import math
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(reverse=True)
k=ab[0][0]
ab.sort(reverse=True,key=lambda x:x[1])
ans=0
while h>0:
if ans==n:
break
if k<=ab[ans][1]:
h-=ab[ans][1]
ans+=1
else:
break
if h<=0:
print(ans)
else:
print(ans+math.ceil(h/k))
Recommended Posts