当前位置: 首页 > 后端技术 > Python

RoundA2020-KickStart2020-python版代码

时间:2023-03-26 12:07:13 Python

https://codingcompetitions.wi...AllocationT组数据,每组两行,第一行N,B表示有N栋房子在售,你拥有钱是B,第二行是N个整数,代表每间房子的价格。找出最多可以购买的房屋数量。T=int(input())fortinrange(T):N,B=map(int,input().split())a=list(map(int,input().split()))a.sort()cnt=0forxina:ifB>1ks=0forddind:ifdd<=m:breakks+=math.ceil(dd/m)-1ifks>K:l=m+1else:r=mprint('Case#%d:%d'%(t+1,r))Bundling将N个字符串分成K组(N必须是可整除的由K).每组的分数是该组中字符串的最长公共前缀的总和。求全局分数最大字母树T=int(input())forttinrange(T):N,K=map(int,input().split())ss=[]for_inrange(N):ss.append(input())base=ord('A')类TrieNode:def__init__(self):self.cnt=0self.children=[None]*26defadd(self,s):self.cnt+=1如果不是s:如果不是self.children[i]:self.children[i]=TrieNode()self.children[i].add(s[1:])root=TrieNode()forsinss:t=rootforchins:t.cnt+=1i=ord(ch)-base如果不是t.children[i]:t.children[i]=TrieNode()t=t.children[i]t.cnt+=1cnt=0root.cnt=0stack=[root]whilestack:t=stack.pop()cnt+=t.cnt//Kforcint.children:ifcandc.cnt>=K:stack.append(c)print('案例#%d:%d'%(tt+1,cnt))递归(测试数据2会超过递归层限制)T=int(input())fortinrange(T):N,K=map(int,input().split())ss=[]for_inrange(N):ss.append(input())ss.sort()cnt=[0]deffind(i,j,k):s=iwhiles=len(ss[s]):s+=1x=swhiles=K:cnt[0]+=(x-s)//Kfind(s,x,k+1)s=xfind(0,len(ss),0)print('Case#%d:%d'%(t+1,cnt[0]))欢迎来到我的博客:https://codeplot.top/我的博客问题分类:https://codeplot.顶部/类别/%E5%88%B7%E9%A2%98/