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


bryan931218@gmail.com (游翔宇)


 

請問Python有能AC的解法嗎?

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

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


bryan931218@gmail.com (游翔宇)


 

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


 

請問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 !!