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