国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

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的使用

  找最大值的思維通路

  命名變量、函數更加規范

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邵阳市| 临湘市| 尼玛县| 察隅县| 洪洞县| 韶关市| 黔南| 中山市| 鄢陵县| 麻城市| 乐山市| 兰坪| 绥德县| 诸暨市| 大悟县| 梓潼县| 光山县| 行唐县| 波密县| 依兰县| 大田县| 泰安市| 宕昌县| 林周县| 北碚区| 华阴市| 四子王旗| 西昌市| 罗平县| 吴桥县| 噶尔县| 普兰店市| 大同县| 重庆市| 江阴市| 偏关县| 剑河县| 石林| 绵竹市| 新丰县| 伊宁县|