AtCoder Beginner Contest 046 Review of past questions

Time required

スクリーンショット 2020-02-27 14.45.30.png

Impressions

I'm glad that the D problem wasn't that difficult because it was an idea game, but it took a lot of time because an error occurred due to the ceil function in the C problem.

Problem A

It is easy to distinguish cases if a, b, and c are all the same.

answerA.py


a,b,c=map(int,input().split())
if a==b and b==c:
    print(1)
elif a==b or b==c or c==a:
    print(2)
else:
    print(3)

B problem

You can decide the colors in order from the front. There are k ways only at the beginning, and after that, k-1 ways can be obtained by using colors other than the immediately preceding color.

answerB.py


n,k=map(int,input().split())
print(k*((k-1)**(n-1)))

C problem

From the ratio of the number of votes obtained in the i-th time, the actual number of votes obtained is Ti * x, Ai * x (x is an integer of 1 or more), and when the number of votes immediately before is T, A, Ti * x> = T , Ai * x> = A, should hold. Therefore, x is the larger of ceil (T / Ti) and ceil (A / Ai). However, ** in Python, the result of division is float type instead of int **, so there will be an error when the number is large. Therefore, do not use the ceil function here. Therefore, by using-((-X) // Y) instead of ** ceil (X / Y) **, the calculation can be performed without error.

answerC.py


n=int(input())
nt,na=map(int,input().split())
for i in range(n-1):
    t,a=map(int,input().split())
    #There is an error in the part where x is calculated
    #x=max(ceil(nt/t),ceil(na/a))
    x=-min((-nt)//t,(-na)//a)
    nt,na=x*t,x*a
print(nt+na)

D problem

First of all, I want to put out as many pars as possible ** (n-n // 2 times), so considering such a method, the method of putting out alternately with gooper gooper gooper ... is the most common method. I didn't have much time because I was in the wild, so I submitted it with this appropriate consideration during the virtual console.

Since the number of times Goo and Par are issued has been decided, consider that the order in which Goo and Par are issued is not related to the score. Considering how to put out the hand, if you put out a par while the opponent is putting out a goo, +1 if you put out a goo, 0 if you put out a par, if you put out a par while the opponent is putting out a par, 0 goo If you issue, it will be -1. In other words, in any case, if you put out a goo, you will have a -1 effect ** on the whole ** compared to if you put out a par. Therefore, when the number of times Goo and Par are issued is decided, it can be said that the score is not related to the order of Goo and Par. (Since it is written sensuously, please refer to Answer for details.)

If you implement the above, it will be as follows (just count the score when alternating with Gooper Gooper Gooper ...).

answerD.py


s=input()
n=len(s)
ans=0
for i in range(n):
    if i%2==0:
        if s[i]=="p":
            ans-=1
    else:
        if s[i]=="g":
            ans+=1
print(ans)

Recommended Posts

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 127 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
AtCoder Beginner Contest 098 Review of past questions
AtCoder Beginner Contest 114 Review of past questions
AtCoder Beginner Contest 045 Review of past questions