Python0分全RE求调,样例都能过
查看原帖
Python0分全RE求调,样例都能过
1037637
Akabane_Karuma楼主2023/9/6 20:48
def do_card(place):
    global p, fail
    if double:
        if player[place][5]:
            if 'PASS' in player[place][5]:
                push_card(place, 6, 'PASS')
            elif 'TURN' in player[place][5]:
                push_card(place, 6, 'TURN')
            else:
                push_card(place, 6, 'DOUBLE')
        else:
            maxn = 300
            max_kind = 0
            card_num = 0
            if player[place][3]:
                maxn = p // 2
                max_kind = 4
                card_num = 2
            if player[place][1]:
                if maxn > p-max(player[place][1]):
                    maxn = p-max(player[place][1])
                    max_kind = 2
                    card_num = max(player[place][1])
            if player[place][0]:
                if maxn > p+min(player[place][0]):
                    maxn = p+min(player[place][0])
                    max_kind = 1
                    card_num = min(player[place][0])
            if player[place][2]:
                if maxn > p*2:
                    maxn = p*2
                    max_kind = 3
                    card_num = 2
            if player[place][4]:
                if maxn > min(player[place][4]):
                    maxn = min(player[place][4])
                    max_kind = 5
                    card_num = min(player[place][4])
            push_card(place, max_kind, card_num)
    else:
        maxn = -500000
        max_kind = 0
        card_num = 0
        if player[place][2]:
            if maxn < p*2 < 100:
                maxn = p*2
                max_kind = 3
                card_num = 2
        if player[place][0]:
            for i1 in player[place][0]:
                if maxn < p+i1 < 100:
                    maxn = p+i1
                    max_kind = 1
                    card_num = i1
        if player[place][1]:
            if maxn < p-min(player[place][1]):
                maxn = p-min(player[place][1])
                max_kind = 2
                card_num = min(player[place][1])
        if player[place][3]:
            if maxn < p//2:
                maxn = p//2
                max_kind = 4
                card_num = 2
        if player[place][4]:
            if maxn < max(player[place][4]):

                maxn = max(player[place][4])
                max_kind = 5
                card_num = max(player[place][4])
        if maxn == -500000:
            if player[place][5]:
                if 'PASS' in player[place][5]:
                    push_card(place, 6, 'PASS')
                elif 'TURN' in player[place][5]:
                    push_card(place, 6, 'TURN')
                else:
                    push_card(place, 6, 'DOUBLE')
            else:
                fail = place
                print('%s lost the game.' % (name[place]))
                player[place] = [[], [], [], [], [], []]
                for i1 in range(3):
                    get_card(place, card[0])
                    del card[0]
                return
        else:
            push_card(place, max_kind, card_num)


def get_card(place, cards):
    if cards[0] == 'A':
        player[place][0].append(int(cards[1:]))
        player[place][0].sort()
    elif cards[0] == 'B':
        player[place][1].append(int(cards[1:]))
        player[place][1].sort()
    elif cards == 'C2':
        player[place][2].append(2)
    elif cards == 'D2':
        player[place][3].append(2)
    elif cards[0] == 'E':
        player[place][4].append(int(cards[1:]))
        player[place][4].sort()
    else:
        player[place][5].append(cards)


def push_card(place, kind, cards):
    global p, double, turn, fail
    doubled = False
    if double:
        doubled = True
    del player[place][kind-1][player[place][kind-1].index(cards)]
    if kind == 1:
        p += cards
        card_name = 'A'+str(cards)
    elif kind == 2:
        p -= cards
        card_name = 'B'+str(cards)
    elif kind == 3:
        p *= 2
        card_name = 'C2'
    elif kind == 4:
        p //= 2
        card_name = 'D2'
    elif kind == 5:
        p = cards
        card_name = 'E'+str(cards)
    else:
        if cards == 'TURN':
            turn = bool((int(turn)+1) % 2)
        elif cards == 'DOUBLE':
            double = True
        card_name = cards
    if p >= 100:
        fail = place
        print('%s lost the game.' % (name[place]))
        player[place] = [[], [], [], [], [], []]
        for i1 in range(3):
            get_card(place, card[0])
            del card[0]
        return
    print('%s used %s,now p=%d.' % (name[place], card_name, p))
    get_card(place, card[0])
    del card[0]
    if doubled and kind != 6:
        double = False
        do_card(place)
    elif turn:
        do_card((place+1) % n)
    else:
        do_card((place-1) % n)


inp = input().split()
n = int(inp[0])
m = int(inp[1])
name = []
player = []
fail = 0
for i in range(n):
    player.append([[], [], [], [], [], []])
    inp = input().split()
    name.append(inp[0])
    for j in range(1, 4):
        get_card(i, inp[j])
card = input().split()
for i in range(m):
    print('Round %d:' % m)
    over = False
    turn = True  # True为顺时针,False为逆时针
    double = False
    p = 0
    do_card(fail)
# 经典大模拟调试不给注释.jpg

2023/9/6 20:48
加载中...