QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#322741 | #4858. Poker Game: Decision | fermion5 | TL | 10ms | 9576kb | Python3 | 4.8kb | 2024-02-07 16:32:00 | 2024-02-07 16:32:01 |
Judging History
answer
import sys
input = sys.stdin.readline
card = {'S':0, 'H':100, 'C':200, 'D':300, 'A':14, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13}
def cards_shape_1(cards_number):
if cards_number[-1] - cards_number[0] == 4:
if cards_number[-1] == 14:
return 10000000
return 9000000 + cards_number[-1] * 100
if cards_number[-2] - cards_number[0] == 3 and cards_number[-1] - cards_number[0] == 12:
return 9000000
ret = 6000000
for i in range(5):
ret += cards_number[i] * (15 ** i)
return ret
def cards_number_2(cards_number):
if cards_number[0] != cards_number[1] == cards_number[-1]:
return 8000000 + cards_number[-1] * 100 + cards_number[0]
if cards_number[0] != cards_number[2] == cards_number[3]:
return 7000000 + cards_number[-1] * 100 + cards_number[0]
if cards_number[0] == cards_number[2] != cards_number[3]:
return 7000000 + cards_number[0] * 100 + cards_number[-1]
return 8000000 + cards_number[0] * 100 + cards_number[-1]
def cards_number_3(cards_number):
for i in range(3):
if cards_number[i] == cards_number[i + 1] == cards_number[i + 2]:
if i == 1:
return 4000000 + cards_number[i] * 10000 + cards_number[-1] * 100 + cards_number[0]
return 4000000 + cards_number[i] * 10000 + cards_number[i - 1] * 100 + cards_number[i - 2]
if cards_number[0] != cards_number[1]:
return 3000000 + cards_number[-1] * 10000 + cards_number[1] * 100 + cards_number[0]
if cards_number[-1] != cards_number[-2]:
return 3000000 + cards_number[-2] * 10000 + cards_number[0] * 100 + cards_number[-1]
return 3000000 + cards_number[-1] * 10000 + cards_number[0] * 100 + cards_number[2]
def cards_number_4(cards_number):
for i in range(4):
if cards_number[i] == cards_number[i + 1]:
same_number = cards_number[i]
break
ret = 2000000 + same_number * 10000
j = 2
for k in range(4, i + 1, -1):
ret += cards_number[k] * (15 ** j)
j -= 1
for k in range(i - 1, -1, -1):
ret += cards_number[k] * (15 ** j)
j -= 1
return ret
def cards_number_5(cards_number):
if cards_number[-1] - cards_number[0] == 4:
ret = 5000000
for i in range(5):
ret += cards_number[i] * (15 ** i)
return ret
if cards_number[-2] - cards_number[0] == 3 and cards_number[-1] - cards_number[0] == 12:
ret = 5000001
for i in range(4):
ret += cards_number[i] * (15 ** (i + 1))
return ret
ret = 1000000
for i in range(5):
ret += cards_number[i] * (15 ** i)
return ret
switch_case_dict = {2:cards_number_2, 3:cards_number_3, 4:cards_number_4, 5:cards_number_5}
def type_decision(cards):
cards_number = sorted([i % 100 for i in cards])
cards_shape = set([i // 100 for i in cards])
len_cards_number, len_cards_shape = len(set(cards_number)), len(cards_shape)
if len_cards_shape == 1:
return cards_shape_1(cards_number)
return switch_case_dict.get(len_cards_number)(cards_number)
def dfs(A, B, C, A_bit):
global score
if len(A) == 5:
if A_bit in score.keys():
return score[A_bit]
A_score, B_score = type_decision(A), type_decision(B)
if A_score < B_score:
score[A_bit] = -1
return -1
if A_score == B_score:
score[A_bit] = 0
return 0
score[A_bit] = 1
return 1
res = -1
for i in C:
A.append(i[0])
A_bit += 2 ** i[1]
p_res = -1
for j in C:
if i[1] != j[1]:
B.append(j[0])
p_res = max(p_res, -dfs(A, B, C - {i, j}, A_bit))
B.pop()
if p_res > 0:
break
A.pop()
A_bit -= 2 ** i[1]
if p_res < 0:
res = 1
break
if p_res == 0:
res = 0
return res
def word_to_number(words):
ret = []
for i in words:
k = 0
for j in i:
k += card[j]
ret.append(k)
return ret
def word_to_number_and_index(words):
ret = []
for i in range(6):
k = 0
for j in words[i]:
k += card[j]
ret.append((k, i))
return ret
for _ in range(int(input())):
A_words = list(input().rstrip().split())
B_words = list(input().rstrip().split())
C_words = list(input().rstrip().split())
A, B, C = word_to_number(A_words), word_to_number(B_words), set(word_to_number_and_index(C_words))
score = {}
part_res = dfs(A, B, C, 0)
if part_res > 0:
print('Alice')
elif part_res == 0:
print('Draw')
else:
print('Bob')
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 9576kb
input:
9 JC 4H TS 5D JS JH JD 4S 4C 4D JC 4H TS 5D TH TC TD 5S 5H 5C JC 4H TS 5D 4S JS 5S TH TC TD 7C 3C 7H TH 3S 3H 3D 2C 4H 5S 7C 3C 7H TH 2H 4H 5H 6H 8H 9H 7C 3C 7H TH TS 3S 2S 2H 4C 4D 2D KH 4D JC 2S 2H 2C KS KC KD 2D KH 4D JC 4S 4H 4C JS JH JD 2D KH 4D JC 2S KS 4S JS JH JD
output:
Alice Bob Draw Alice Bob Draw Alice Bob Draw
result:
ok 9 lines
Test #2:
score: 0
Accepted
time: 10ms
memory: 9496kb
input:
1 AS 2H 2S 6H 3S 3H 4S 4H 5S 5H
output:
Bob
result:
ok single line: 'Bob'
Test #3:
score: 0
Accepted
time: 10ms
memory: 9488kb
input:
1 5D 9H KC 6H 9C QH JH 3C AC 9S
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: -100
Time Limit Exceeded
input:
100000 5C JS KS 7S 4D 2D KH 6S 6D 6H 2C KS 7D 5D 5S AH 3S 9C JH 5H 9D 4D 3H TS 2D 2C 7H 3D AH 3S KS 8H 7H QD TH 4H QS 8S 6D TD JS 8D 4H 2S AH 2H 2C 6S 4C 8S JS KD 4S 2D JH 4C 6S QD AH 7C 9D 4H QH JS KH QC 6S 5D JC AD KD 5D 4C TC 4H 2C TD 7S 6S QH 3C 5C QC 9D QH 5D AC 7D 8C 8S 4S 6H 9C 8C JC 7S QH 6C...
output:
Bob Bob Bob Alice Bob Alice Bob Bob Alice Alice Alice Alice Bob Alice Alice Alice Alice Alice Bob Bob Alice Bob Bob Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Bob Alice Alice Bob Bob Alice Alice Bob Bob Bob Alice Alice Alice Bob Bob Alice Alice Alice Alice Alice Alice Al...