Technocup 2017 - Elimination Round 1 参加記

はい。 ox---- (0/0) 1182(-16)
http://codeforces.com/contest/727
Aのみ1完でした。。Bは問題文解読に失敗。Cは面白そうだったけどflushする問題はよくわからなかったのでスルーしました。

A. Transformation: from A to B

ざっくりと大意

・aから始めて2倍にするか、10倍にして更に1を足すかの操作を繰り返してbに出来るか。

Python2

a,b=map(int,raw_input().split())
d={a:[a]}
t=set([a])
while 1:
    i=t.pop()
    if i*2<=b and i*2 not in d:
        d[i*2]=d[i]+[i*2]
        if i*2==b:
            print 'YES'
            print len(d[i*2])
            for j in d[i*2]:
                print j,
            exit()
        t.add(i*2)
    if i*10+1<=b and i*10+1 not in d:
        d[i*10+1]=d[i]+[i*10+1]
        if i*10+1==b:
            print 'YES'
            print len(d[i*10+1])
            for j in d[i*10+1]:
                print j,
            exit()
        t.add(i*10+1)
    if len(t)==0:
        print 'NO'
        exit()

setから何が出てきてるか分からないけど幅優先っぽい感じで2倍と10倍+1の両方試した結果をbより小さいものは戻して、大きいものは捨ててたらACになった。

B. Bill Total Value

ざっくりと大意

・品名と金額が1行で羅列されているので合計金額を求める。
・品名は英小文字のみで記述される、金額も不正な書式のものはデータに含まれないことが保証されている。
・金額の書式はドル部分が3桁区切りでセントがある場合は末尾に2桁です。区切りは全て'.'です。
・百万ドル五セントだと1.000.000.05になる。セントがある場合は2桁表記で末尾に。ない場合は書かない。

Python2

s=raw_input()
s+='$'
tmp=''
l=[]
ans=[0]*3
a,b=[0],[0]*6
for i in s:
    if i.isdigit() or i=='.':
        tmp+=i
    else:
        if len(tmp):
            l.append(tmp)
        tmp=''
for i in l:
    t=i.split('.')
    if len(t)==1:
        b[0]+=int(t[0])
    elif len(t)>1:
        if len(t[-1])==2:
            a[0]+=int(t[-1])
            for p,j in enumerate(t[::-1]):
                if p>0:
                    b[p-1]+=int(j)
        else:
            for p,j in enumerate(t[::-1]):
                b[p]+=int(j)
b[0]+=a[0]/100
a[0]=a[0]%100
for p,i in enumerate(b):
    if p<4:
        b[p+1]+=b[p]/1000
        b[p]=b[p]%1000
while 1:
    if b[-1]==0 and len(b)>1:
        b.pop(-1)
    else:
        break
ans=''
for i in b[::-1]:
    if ans=='':
        ans=str(i)
    else:
        tmp=str(i)
        tmp='0'*(3-len(tmp))+tmp
        ans+='.'+tmp
if a[0]>0:
    tmp=str(a[0])
    if len(tmp)==1:
        ans+='.'+'0'+tmp
    else:
        ans+='.'+tmp
print ans

金額だけ抜く文字列の扱いと、ドル・セント部分の計算をなんとかすればなんとかなると思う。コンテスト中は金額の書式の意味がわかってなくてWAしたけど。。。