[PYTHON] [Professional competition] I tried At Coder Beginner Contest 175 (A ~ C)

We participated in AtCoder Beginner Contest 171. I was able to solve problems A to C. I will write down my thoughts at that time.

A - Rainy Season Returns the number of consecutive Rs from a character string of length 3. I pushed it.

S = input()
if 'RRR' in S:
    print(3)
elif 'RR' in S:
    print(2)
elif 'R' in S:
    print(1)
else:
    print(0)

B - Making Triangle A length list L of N bars is given. Select three of them and return the number of combinations that meet the conditions.

I brute-forced the combinations and used itertools.combinations for that. To find out how to use it during the competition ... itertools.combinations(N,r) Returns a list of r combinations to choose from list N. Example: combinations (range (5), 3) → (0,1,2), (0,1,3), (0,1,4), (0,2,3), (0,2,4) ), (0,3,4), (1,2,3), (1,2,4), (1,3,4), (2,3,4)

import itertools
N = int(input())
L = list(map(int, input().split()))

count = 0
for i in itertools.combinations(range(N), 3):
    Lx = sorted([L[i[0]], L[i[1]], L[i[2]]])
    if not (Lx[0] == Lx[1] or Lx[1] == Lx[2] or Lx[2] == Lx[0]):
        if Lx[0] + Lx[1] > Lx[2] :
            count += 1
print(count)

C - Walking Takahashi $ X, K, and D $ are the initial position, the number of movements, and the movement distance, respectively. The movement direction can be selected from positive or negative, and it is closest to 0.

Let $ i $ be the number of positive moves and the final position be $ d $

X + iD - \left((K-i)D\right) = d\\
X/D + (2i - K) = d/D\\
\frac{X/D - K}{2} + i = d/2D\\

The absolute value of $ d $ is close to $ 0 $ ⇒ $ \ frac {X / D --K} {2} + i ; (i = 0,1, \ ldots, K) Find $ i $ where $ is closest to $ 0 $. ⇒ Put $ \ frac {X / D-K} {2} = {\ rm dist} $ and put it

if dist > 0
 ⇒ i = 0
else if dist + K < 0
 ⇒ i = K
else
 ⇒ i = -round(dist)

MeetiAt that time|d|To ask.

X, K, D = list(map(int, input().split()))

dist= (X/D-K)/2

if -dist > K :
    i = K
elif dist > 0 :
    i = 0
else :
    i = -round(dist)

print(abs(X + i*D - ((K-i)*D)))

the end

I haven't done it since the D problem ...

Recommended Posts

[Professional competition] I tried At Coder Beginner Contest 175 (A ~ C)
[Professional competition practice] I tried At Coder Beginner Selection
[Professional competition practice] I tried AtCoder Beginner Contest 171
Brown coder tried to solve Panasonic Contest 2020A ~ C
[At Coder] Beginner Contest 175 ABCD python Solution introduction
I tried adding a Python3 module in C
[Python] [BFS] At Coder Beginner Contest 168-D [.. Double Dots]
AtCoder Beginner Contest 177 Problem C I tried to find out why it was wrong
AtCoder Beginner Contest 166 A Explanation of Problem "A? C" (Python3, C ++, Java)
AtCoder Beginner Contest 167 A Problem "Registration" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest # 002 C Problem
When I tried the AtCoder Beginner Contest, it was a terrible result, so I look back
I tried Python C extension
A python beginner tried to intern at an IT company
AtCoder Beginner Contest 170 A Problem "Five Variables" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 169 A Explanation of Problem "Multiplication 1" (Python3, C ++, Java)
AtCoder Beginner Contest 176 A Explanation of problem "Takoyaki" (Python3, C ++, Java)
I tried scoring a transvestite contest using Face ++'s Detect API
AtCoder Beginner Contest 175 A Problem "Rainy Season" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 174 A Problem "Air Conditioner" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 174 C Problem (Python)
AtCoder Beginner Contest 177 A Problem "Don't be late" Explanation (Python3, C ++, Java)
I tried to make a face diagnosis AI for a female professional golfer ①
I tried to make a face diagnosis AI for a female professional golfer ②
AtCoder Beginner Contest 165 A Problem "We Love Golf" Explanation (Python3, C ++, Java)
I tried to create a linebot (implementation)
I tried to create a linebot (preparation)
I tried playing a ○ ✕ game using TensorFlow
I tried drawing a line using turtle
Beginner: I made a launcher using dictionary
I tried a functional language with Python
I tried to make a Web API
I tried using pipenv, so a memo
I tried benchmarking a web application framework
I tried 3D detection of a car
A python beginner tried to intern at an IT company [Day 2 chatbot survey]
A python beginner tried to intern at an IT company [Day 1 development process]