QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#82047 | #4858. Poker Game: Decision | Sorting | WA | 21ms | 11188kb | C++14 | 7.5kb | 2023-02-26 23:45:17 | 2023-02-26 23:45:21 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
using namespace std;
int alice[2], bob[2];
int shared[6];
pair<int, int> p[14][14][14][14][14][2];
void init(){
static int a[5];
for(int a0 = 1; a0 <= 13; ++a0)
for(int a1 = 1; a1 <= 13; ++a1)
for(int a2 = 1; a2 <= 13; ++a2)
for(int a3 = 1; a3 <= 13; ++a3)
for(int a4 = 1; a4 <= 13; ++a4){
for(int a_flush = 0; a_flush <= 1; ++a_flush){
a[0] = a0;
a[1] = a1;
a[2] = a2;
a[3] = a3;
a[4] = a4;
sort(a, a + 5);
bool a_straight = true;
for(int i = 0; i < 4; ++i)
a_straight &= (a[i] == a[i - 1] + 1) || (a[i] == 1 && a[i - 1] == 13);
auto &ans = p[a0][a1][a2][a3][a4][a_flush];
int a_score = 0;
if(a_straight && a_flush)
a_score = a[0];
if(a_score){
ans = {9, a_score};
continue;
}
if(a[0] == a[3])
a_score = 16 * a[0] + a[4];
else if(a[1] == a[4])
a_score = 16 * a[1] + a[0];
if(a_score){
ans = {8, a_score};
continue;
}
if(a[0] == a[2] && a[3] == a[4])
a_score = 16 * a[0] + a[3];
else if(a[0] == a[1] && a[2] == a[4])
a_score = 16 * a[2] + a[0];
if(a_score){
ans = {7, a_score};
continue;
}
if(a_flush)
a_score = 16 * 16 * 16 * 16 * a[0] + 16 * 16 * 16 * a[1] + 16 * 16 * a[2] + 16 * a[3] + a[4];
if(a_score){
ans = {6, a_score};
continue;
}
if(a_straight)
a_score = a[0];
if(a_score){
ans = {5, a_score};
continue;
}
if(a[0] == a[2])
a_score = 16 * 16 * a[0] + 16 * a[3] + a[4];
else if(a[1] == a[3])
a_score = 16 * 16 * a[1] + 16 * a[0] + a[4];
else if(a[2] == a[4])
a_score = 16 * 16 * a[2] + 16 * a[0] + a[1];
if(a_score){
ans = {4, a_score};
continue;
}
if(a[0] == a[1] && a[2] == a[3])
a_score = 16 * 16 * a[0] + 16 * a[2] + a[4];
else if(a[0] == a[1] && a[3] == a[4])
a_score = 16 * 16 * a[0] + 16 * a[3] + a[2];
else if(a[1] == a[2] && a[3] == a[4])
a_score = 16 * 16 * a[1] + 16 * a[3] + a[0];
if(a_score){
ans = {3, a_score};
continue;
}
if(a[0] == a[1])
a_score = a[0] * 16 * 16 * 16 + a[2] * 16 * 16 + a[3] * 16 + a[4];
else if(a[1] == a[2])
a_score = a[1] * 16 * 16 * 16 + a[0] * 16 * 16 + a[3] * 16 + a[4];
else if(a[2] == a[3])
a_score = a[2] * 16 * 16 * 16 + a[0] * 16 * 16 + a[1] * 16 + a[4];
else if(a[3] == a[4])
a_score = a[3] * 16 * 16 * 16 + a[0] * 16 * 16 + a[1] * 16 + a[2];
if(a_score){
ans = {2, a_score};
continue;
}
a_score = a[0] * 16 * 16 * 16 * 16 + a[1] * 16 * 16 * 16 + a[2] * 16 * 16 + a[3] * 16 + a[4];
ans = {1, a_score};
}
}
}
int outcome(int state){
static int a[5], b[5];
a[0] = alice[0];
a[1] = alice[1];
b[0] = bob[0];
b[1] = bob[1];
int cnt_a = 2, cnt_b = 2;
for(int i = 0; i < 6; ++i){
if(state >> (2 * i) & 1)
a[cnt_a++] = shared[i];
else
b[cnt_b++] = shared[i];
}
bool a_flush = true;
for(int i = 0; i < 4; ++i)
a_flush &= (a[i] & 3) == (a[i + 1] & 3);
bool b_flush = true;
for(int i = 0; i < 4; ++i)
b_flush &= (b[i] & 3) == (b[i + 1] & 3);
for(int i = 0; i < 5; ++i){
a[i] >>= 2;
b[i] >>= 2;
}
auto score_a = p[a[0]][a[1]][a[2]][a[3]][a[4]][a_flush];
auto score_b = p[b[0]][b[1]][b[2]][b[3]][b[4]][b_flush];
return (score_a > score_b) - (score_a < score_b);
}
int recurse(int state){
int turns = __builtin_popcount(state);
if(turns == 6){
// cout << state << " - " << outcome(state) << endl;
return outcome(state);
}
int ans;
bool pl = turns & 1;
ans = -1 + 2 * pl;
for(int i = 0; i < 6; ++i){
if(state >> (2 * i) & 3)
continue;
int cand = recurse(state + (1 << (2 * i + pl)));
if(cand == 1 - 2 * pl)
return cand;
if(pl)
ans = min(ans, cand);
else
ans = max(ans, cand);
}
return ans;
}
int string_to_card(const string &s){
int ans = 0;
if('2' <= s[0] && s[0] <= '9')
ans = s[0] - '0' - 1;
else if(s[0] == 'T')
ans = 9;
else if(s[0] == 'J')
ans = 10;
else if(s[0] == 'Q')
ans = 11;
else if(s[0] == 'K')
ans = 12;
else
ans = 13;
ans *= 4;
if(s[1] == 'S')
ans += 0;
else if(s[1] == 'H')
ans += 1;
else if(s[2] == 'C')
ans += 1;
else
ans += 2;
return ans;
}
void solve(){
for(int i = 0; i < 2; ++i){
string s;
cin >> s;
alice[i] = string_to_card(s);
}
for(int i = 0; i < 2; ++i){
string s;
cin >> s;
bob[i] = string_to_card(s);
}
for(int i = 0; i < 6; ++i){
string s;
cin >> s;
shared[i] = string_to_card(s);
}
int answer = recurse(0);
if(answer == 1)
cout << "Alice\n";
else if(answer == 0)
cout << "Draw\n";
else
cout << "Bob\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
init();
int t;
cin >> t;
while(t--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 21ms
memory: 11188kb
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: -100
Wrong Answer
time: 20ms
memory: 10968kb
input:
1 AS 2H 2S 6H 3S 3H 4S 4H 5S 5H
output:
Draw
result:
wrong answer 1st lines differ - expected: 'Bob', found: 'Draw'