Link:
https://www.hackerrank.com/challenges/acm-icpc-team/submissions/code/11617807
def count_max_topics(konw_topics):
max_topics = 0
max_teams = 0
for i, person1 in enumerate(konw_topics): # enumer的用法学习
for j, person2 in enumerate(konw_topics[i+1:]):
bin1 = int(person1, 2) # 二进制的转换
bin2 = int(person2, 2)
topics = bin(bin1 | bin2).count('') if topics > max_topics: # 找最大值的一个通用思路
max_topics = topics
max_teams = 1
elif topics == max_topics:
max_teams += 1 print max_topics
print max_teams def main():
n, m = map(int, raw_input().strip().split(' ')) #双位输入的模板
konw_topics = [] # 用list合适
for _ in range(n):
konw_topics.append(raw_input().strip()) count_max_topics(konw_topics) # func设置分散,这样更易读和理解 main()
问题本质
二进制运算
Subarray计算
循环记录最大值
学习
enumerate
二进制的转换 int(,2)
熟悉dash的使用
找最大值的思维通路
命名变量、函数更加规范