https://code.google.com/codejam/contest/10284486/dashboard#s=p1&a=1
这次的好难,只看了前2题,只会用暴力写small
Problem A. No Nine
import sys
#file = 'test'
file = 'small'
#file = 'large'
ques = 'A'
res = []
def slove(l,r):
t = 0
for i in range(l,r+1):
if '9' not in str(i) and i%9!=0: t+=1
return t
sys.stdin = open('%s-%s-practice.in'%(ques, file), 'r')
cases = int(input())
for i_ in range(cases):
a=list(map(int,input().strip().split(' ')))
res.append(slove(a[0],a[1]))
fp = open('%s-%s-practice.out'%(ques, file), 'w')
for i_,c in enumerate(res):
fp.write('Case #%d: %d\n'%(i_+1,c))
Problem B. Sherlock and the Bit Strings
import sys
#file = 'test'
file = 'small'
#file = 'large'
ques = 'B'
res = []
def slove(a,n,k,p):
res=''
add=[(at[0],at[2]) for at in a]
add.sort()
j = 0
for i in range(n):
if j<len(add) and i==add[j][0]-1:
res += '1' if add[j][1] else '0'
j+=1
elif p>2**(n-1-i-k+j):
p-=2**(n-1-i-k+j)
res+='1'
else:
res+='0'
assert len(res)==n
return res
sys.stdin = open('%s-%s-practice.in'%(ques, file), 'r')
cases = int(input())
for i_ in range(cases):
# print(i_/cases)
n,k,p=list(map(int,input().strip().split(' ')))
a=[]
for _ in range(k):
a.append(list(map(int,input().strip().split(' '))))
res.append(slove(a,n,k,p))
fp = open('%s-%s-practice.out'%(ques, file), 'w')
for i_,c in enumerate(res):
fp.write('Case #%d: %s\n'%(i_+1,c))
网友评论