首页 > 学院 > 开发设计 > 正文

ACMICPCTeam

2019-11-14 17:12:17
字体:
来源:转载
供稿:网友

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 = topics12                 max_teams = 113             elif topics == max_topics:14                 max_teams += 115 16     PRint max_topics17     print max_teams18 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的使用

  找最大值的思维通路

  命名变量、函数更加规范

  


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表