-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
40 lines (38 loc) · 996 Bytes
/
main.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
# Author : Qi Zhang
# Date : 2018-12-11
# 此处可 import 模块
"""
@param string line 为单行测试数据
@return string 处理后的结果
"""
def solution(line):
nums = [int(i) for i in line.rstrip().split(",")]
def divide(start, end):
if start >= end:
return 0
m = (start + end) / 2
ans = 0
ans += divide(start, m)
ans += divide(m+1, end)
i = start
j = m+1
tmp = []
while(i <= m and j <= end):
if nums[i] <= nums[j]:
tmp.append(nums[i])
i += 1
else:
ans += m - i + 1
tmp.append(nums[j])
j += 1
while(i <= m):
tmp.append(nums[i])
i += 1
while(j <= end):
tmp.append(nums[j])
j += 1
for k in range(start, end+1):
nums[k] = tmp[k-start]
return ans
ans = divide(0, len(nums)-1)
return str(ans)