https://www.codingame.com/training/medium/aneo

 

Practice Loops and Intervals with the exercise "ANEO Sponsored Puzzle"

Want to practice Loops and intervals? Try to solve the coding challenge "ANEO Sponsored Puzzle".

www.codingame.com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
import math
 
# traffic lights를 통과할 수 있는 최대 속도 구하기.
 
speed = int(input())
 
light_count = int(input())      # 신호등 개수
 
light = ['']*light_count
for i in range(light_count):
    light[i] = ['']*2
   
for i in range(light_count):
    distance, duration = [int(j) for j in input().split()]
    light[i][0= distance
    light[i][1= duration
    
answer = speed
flag = 0
for s in range(speed, 0-1):
    for i in range(light_count):
 
        if (light[i][0]/s*3.6)%(2*light[i][1]) < light[i][1]:
            answer = s
        else:
            s=s-1
            break        # 이 속도로 모든 신호등을 통과할 수 없다면 속도 줄이고 첫 신호등부터 다시.
        
        if i==light_count-1:
            flag = 1    # 모든 신호등을 통과할 수 있는 속도가 찾아졌다!
            
    if flag==1:
        break
    
print(answer)
cs

'python > codinGame' 카테고리의 다른 글

LUMEN  (0) 2020.03.06
GRAFFITI ON THE FENCE  (0) 2020.03.06
Rectangle Partition  (0) 2020.03.06
Defibrillators  (0) 2020.03.03

+ Recent posts