-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathRandom.py
More file actions
38 lines (29 loc) · 1.02 KB
/
Random.py
File metadata and controls
38 lines (29 loc) · 1.02 KB
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
# -*- coding: utf-8 -*-
"""
Problem Statement
Given an array 'D' with n elements: d[0], d[1], ..., d[n-1], you can perform the following two steps on the array.
Randomly choose two indexes (l, r) with l < r, swap (d[l], d[r])
Randomly choose two indexes (l, r) with l < r, reverse (d[l...r]) (both inclusive)
After you perform the first operation a times and the second operation b times, you randomly choose two indices l & r
with l < r and calculate the S = sum(d[l...r]) (both inclusive).
Now, you are to find the expected value of S.
"""
__author__ = 'Danyang'
class Solution(object):
def solve(self, cipher):
"""
main solution function
:param cipher: the cipher
"""
# TODO
if __name__ == "__main__":
import sys
f = open("0.in", "r")
# f = sys.stdin
solution = Solution()
n, a, b = map(int, f.readline().strip().split(' '))
D = map(int, f.readline().strip().split(' '))
cipher = n, a, b, D
# solve
s = "%s\n" % (solution.solve(cipher))
print s,