美文网首页
Kickstart Round B 2018

Kickstart Round B 2018

作者: GoDeep | 来源:发表于2018-07-28 13:01 被阅读0次

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))

相关文章

网友评论

      本文标题:Kickstart Round B 2018

      本文链接:https://www.haomeiwen.com/subject/puemlftx.html