-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpdd1.py
More file actions
executable file
·45 lines (41 loc) · 1.26 KB
/
pdd1.py
File metadata and controls
executable file
·45 lines (41 loc) · 1.26 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
39
40
41
42
43
44
45
#-*- coding:utf-8
def findMostOne(arr, m, n):
most_list = []
for row in range(m):
for col in range(n):
#记住每一行最小的 Index 即可,相同最大情况
if arr[row][col] == 1 and col == n-1:
most_list.append([row+1,m-col])
#更新最大情况
elif arr[row][col] == 1 and col != n-1:
cols = col
most_list = []
most_list.append([row+1,n-col])
break
print most_list
def findMostOneBySum(arr, m, n):
most_row_sum = -1
most_row_index = []
for row in range(m):
tmp = sum(arr[row])
if tmp > most_row_sum:
most_row_sum = tmp
print 'update most to',most_row_sum
most_row_index = []
most_row_index.append(row)
elif tmp == most_row_sum:
print 'dup'
most_row_index.append(row)
return [[index+1,most_row_sum] for index in most_row_index]
if __name__ == '__main__':
arr =[
[0,0,0,0,0,0,0,1,1,1,1,1],
[0,0,0,0,1,1,1,1,1,1,1,1],
[0,0,0,0,0,0,1,1,1,1,1,1],
[0,0,0,0,0,0,0,0,0,1,1,1],
[0,0,0,0,0,0,0,1,1,1,1,1],
[0,0,0,0,1,1,1,1,1,1,1,1]
]
m = 6
n = 12
print findMostOneBySum(arr,m,n)