-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJumping_on_the_Clouds_Revisited.py
97 lines (64 loc) · 2.62 KB
/
Jumping_on_the_Clouds_Revisited.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# A child is playing a cloud hopping game. In this game, there are sequentially numbered clouds that can be thunderheads or cumulus clouds. The character must jump from cloud to cloud until it reaches the start again.
# There is an array of clouds, and an energy level . The character starts from and uses unit of energy to make a jump of size to cloud . If it lands on a thundercloud, , its energy () decreases by additional units. The game ends when the character lands back on cloud .
# Given the values of , , and the configuration of the clouds as an array , determine the final value of after the game ends.
# Example.
# The indices of the path are . The energy level reduces by for each jump to . The character landed on one thunderhead at an additional cost of energy units. The final energy level is .
# Note: Recall that refers to the modulo operation. In this case, it serves to make the route circular. If the character is at and jumps , it will arrive at .
# Function Description
# Complete the jumpingOnClouds function in the editor below.
# jumpingOnClouds has the following parameter(s):
# int c[n]: the cloud types along the path
# int k: the length of one jump
# Returns
# int: the energy level remaining.
# Input Format
# The first line contains two space-separated integers, and , the number of clouds and the jump distance.
# The second line contains space-separated integers where . Each cloud is described as follows:
# If , then cloud is a cumulus cloud.
# If , then cloud is a thunderhead.
# Constraints
# Sample Input
# STDIN Function
# ----- --------
# 8 2 n = 8, k = 2
# 0 0 1 0 0 1 1 0 c = [0, 0, 1, 0, 0, 1, 1, 0]
# Sample Output
# 92
# Explanation
# In the diagram below, red clouds are thunderheads and purple clouds are cumulus clouds:
# game board
# Observe that our thunderheads are the clouds numbered , , and . The character makes the following sequence of moves:
# Move: , Energy: .
# Move: , Energy: .
# Move: , Energy: .
# Move: , Energy: .
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the jumpingOnClouds function below.
def jumpingOnClouds(c, k):
t = 100
p = 0
l = len(c)
if c[p] == 0:t-=1
else:t-=3
p+=k
p = p%l
while p:
if c[p] == 0:t-=1
else:t-=3
p+=k
p = p%l
return t
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nk = input().split()
n = int(nk[0])
k = int(nk[1])
c = list(map(int, input().rstrip().split()))
result = jumpingOnClouds(c, k)
fptr.write(str(result) + '\n')
fptr.close()