ACM ICPC Team

Link:

  https://www.hackerrank.com/challenges/acm-icpc-team/submissions/code/11617807

 1 def count_max_topics(konw_topics):

 2     max_topics = 0

 3     max_teams = 0

 4     for i, person1 in enumerate(konw_topics): # enumer的用法学习

 5         for j, person2 in enumerate(konw_topics[i+1:]):

 6             bin1 = int(person1, 2) # 二进制的转换

 7             bin2 = int(person2, 2)

 8             topics = bin(bin1 | bin2).count('1')

 9 

10             if topics > max_topics: # 找最大值的一个通用思路

11                 max_topics = topics

12                 max_teams = 1

13             elif topics == max_topics:

14                 max_teams += 1

15 

16     print max_topics

17     print max_teams

18 

19 def main():

20     n, m = map(int, raw_input().strip().split(' ')) #双位输入的模板

21     konw_topics = [] # 用list合适

22     for _ in range(n):

23         konw_topics.append(raw_input().strip())

24 

25     count_max_topics(konw_topics) # func设置分散,这样更易读和理解

26 

27 

28 main()

问题本质

  二进制运算

  Subarray计算

  循环记录最大值

学习

  enumerate

  二进制的转换 int(,2)

  熟悉dash的使用

  找最大值的思维通路

  命名变量、函数更加规范

  

你可能感兴趣的:(ICPC)