#26616: python請教tle


andy.lin61013@gmail.com (我是你爸)

學校 : 國立清華大學
編號 : 158445
來源 : [118.166.40.151]
最後登入時間 :
2022-08-02 21:19:43
b594. A Marvelous Pet | From: [36.231.53.155] | 發表日期 : 2021-08-16 19:08

測資大寫迴圈當掉

請問有沒有其他方法!

 
from sys import stdin,exit
for s in stdin:
    if int(s)==0:exit()

    s,seq=int(s),list(range(1,int(s)))
    stop1=int(s/2)
    stop2=int((s+1)/2)
    if s%2==0:del seq[stop1:]
    else:del seq[stop2:]

    cnt=0
    while sum(seq)>=s:
        addnum=0
        for i in seq:
            addnum+=i
            if addnum<s
                continue
            elif addnum==s:
                cnt+=1
                del seq[0]
                break
            elif addnum>s:
                del seq[0]
                break

        if len(seq)==1:
            break
    print(cnt)
 
#26617: Re:python請教tle


asnewchien@gmail.com (david)

學校 : 不指定學校
編號 : 68108
來源 : [1.168.27.116]
最後登入時間 :
2024-03-31 17:58:15
b594. A Marvelous Pet | From: [125.224.194.28] | 發表日期 : 2021-08-16 20:08

這題類似 e626

可參考一下  

 

 
ZeroJudge Forum