#18540: APCS-2016-1029-3定時K彈 NA 70%超時


bryan931218@gmail.com (游翔宇)

學校 : 國立宜蘭高級中學
編號 : 98903
來源 : [140.113.136.219]
最後登入時間 :
2023-09-13 16:25:16
c296. APCS-2016-1029-3定時K彈 -- 2016年10月APCS | From: [111.71.117.67] | 發表日期 : 2019-07-20 14:32

 

請問Python有能AC的解法嗎?

我真的搞不清楚動態規劃是什麼概念

 
#18541: Re:APCS-2016-1029-3定時K彈 NA 70%超時


bryan931218@gmail.com (游翔宇)

學校 : 國立宜蘭高級中學
編號 : 98903
來源 : [140.113.136.219]
最後登入時間 :
2023-09-13 16:25:16
c296. APCS-2016-1029-3定時K彈 -- 2016年10月APCS | From: [111.71.117.67] | 發表日期 : 2019-07-20 14:33

 

請問Python有能AC的解法嗎?

我真的搞不清楚動態規劃是什麼概念


這是我的解法 大測資會超時

import sys

for s in sys.stdin:

    Bomb = []

    now = 0

    s = list(map(int,s.split()))

    N,M,K = s[0],s[1],s[2]

    for i in range(1, N+1):

        Bomb.append(i)

    for i in range(K):

        if now == len(Bomb):

            now = 0

        now+=M-1

        while now >= len(Bomb):

            now-=len(Bomb)

        del Bomb[now]

    if len(Bomb) == 1 or len(Bomb) == now:

        print(Bomb[0])

    else:

        print(Bomb[now])

 

 
#18544: Re:APCS-2016-1029-3定時K彈 NA 70%超時


asnewchien@gmail.com (david)

學校 : 不指定學校
編號 : 68108
來源 : [1.168.27.116]
最後登入時間 :
2024-03-31 17:58:15
c296. APCS-2016-1029-3定時K彈 -- 2016年10月APCS | From: [1.168.25.250] | 發表日期 : 2019-07-20 14:59

 

請問Python有能AC的解法嗎?

我真的搞不清楚動態規劃是什麼概念


這是我的解法 大測資會超時

import sys

for s in sys.stdin:

    Bomb = []

    now = 0

    s = list(map(int,s.split()))

    N,M,K = s[0],s[1],s[2]

    for i in range(1, N+1):

        Bomb.append(i)

    for i in range(K):

        if now == len(Bomb):

            now = 0

        now+=M-1

        while now >= len(Bomb):

            now-=len(Bomb)

        del Bomb[now]

    if len(Bomb) == 1 or len(Bomb) == now:

        print(Bomb[0])

    else:

        print(Bomb[now])

 

while now >= len(Bomb):

    now-=len(Bomb)

改成 


now %= len(Bomb)

速度就差很多了, try it !!

 
ZeroJudge Forum