We participated in AtCorder Beginner Contest 175. It was ABC's 3 questions AC. I'm using Python3.
First, find the number of rains (R). This time, the number of consecutive rains (R) is calculated, so in the case of RSR, the case of answering 1 is processed. One exception is sufficient, as only 3 days of weather will be entered.
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
s=input()
c = s.count("R")
if c == 2 and s[1] == "S":
c += -1
print(c)
if __name__ == "__main__":
main()
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in L:
for j in L:
for k in L:
if i < j and j < k and (i+j) > k and (i+k) > j and (j+k) >i:
ans +=1
print(ans)
if __name__ == "__main__":
main()
Takahashi's behavior patterns can be broadly divided into two. ・ Even if you act K times, you cannot reach 0 from X (as close as possible) ・ It reached 0 from X in less than K times, and returned to near 0 by reciprocating with the remaining number of times. The second pattern is divided according to whether the number of remaining times is even or odd.
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
X,K,D = map(int,input().split())
x = abs(X)
if K * D < x:
ans = x - K * D
else:
shou = x // D
nokori = K - shou
if nokori % 2 == 0:
ans = x % D
else:
ans = abs((x % D) - D)
print(ans)
if __name__ == "__main__":
main()
Recommended Posts