[PYTHON] AtCoder Beginner Contest 085 Review of past questions

Time required

スクリーンショット 2020-03-30 19.02.19.png

Impressions

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.

Problem A

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))

B problem

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)))

C problem

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")

D problem

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

AtCoder Beginner Contest 102 Review of past questions
AtCoder Beginner Contest 072 Review of past questions
AtCoder Beginner Contest 085 Review of past questions
AtCoder Beginner Contest 062 Review of past questions
AtCoder Beginner Contest 113 Review of past questions
AtCoder Beginner Contest 074 Review of past questions
AtCoder Beginner Contest 051 Review of past questions
AtCoder Beginner Contest 127 Review of past questions
AtCoder Beginner Contest 119 Review of past questions
AtCoder Beginner Contest 151 Review of past questions
AtCoder Beginner Contest 075 Review of past questions
AtCoder Beginner Contest 054 Review of past questions
AtCoder Beginner Contest 110 Review of past questions
AtCoder Beginner Contest 117 Review of past questions
AtCoder Beginner Contest 070 Review of past questions
AtCoder Beginner Contest 105 Review of past questions
AtCoder Beginner Contest 112 Review of past questions
AtCoder Beginner Contest 076 Review of past questions
AtCoder Beginner Contest 089 Review of past questions
AtCoder Beginner Contest 069 Review of past questions
AtCoder Beginner Contest 079 Review of past questions
AtCoder Beginner Contest 056 Review of past questions
AtCoder Beginner Contest 087 Review of past questions
AtCoder Beginner Contest 067 Review of past questions
AtCoder Beginner Contest 093 Review of past questions
AtCoder Beginner Contest 046 Review of past questions
AtCoder Beginner Contest 123 Review of past questions
AtCoder Beginner Contest 049 Review of past questions
AtCoder Beginner Contest 078 Review of past questions
AtCoder Beginner Contest 081 Review of past questions
AtCoder Beginner Contest 047 Review of past questions
AtCoder Beginner Contest 060 Review of past questions
AtCoder Beginner Contest 104 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 121 Review of past questions
AtCoder Beginner Contest 126 Review of past questions
AtCoder Beginner Contest 090 Review of past questions
AtCoder Beginner Contest 103 Review of past questions
AtCoder Beginner Contest 061 Review of past questions
AtCoder Beginner Contest 059 Review of past questions
AtCoder Beginner Contest 044 Review of past questions
AtCoder Beginner Contest 083 Review of past questions
AtCoder Beginner Contest 048 Review of past questions
AtCoder Beginner Contest 124 Review of past questions
AtCoder Beginner Contest 116 Review of past questions
AtCoder Beginner Contest 097 Review of past questions
AtCoder Beginner Contest 088 Review of past questions
AtCoder Beginner Contest 092 Review of past questions
AtCoder Beginner Contest 099 Review of past questions
AtCoder Beginner Contest 065 Review of past questions
AtCoder Beginner Contest 053 Review of past questions
AtCoder Beginner Contest 094 Review of past questions
AtCoder Beginner Contest 063 Review of past questions
AtCoder Beginner Contest 107 Review of past questions
AtCoder Beginner Contest 071 Review of past questions
AtCoder Beginner Contest 064 Review of past questions
AtCoder Beginner Contest 082 Review of past questions
AtCoder Beginner Contest 084 Review of past questions
AtCoder Beginner Contest 068 Review of past questions
AtCoder Beginner Contest 058 Review of past questions
AtCoder Beginner Contest 043 Review of past questions