QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#59531 | #4858. Poker Game: Decision | captured# | WA | 7ms | 3588kb | C++14 | 6.0kb | 2022-10-30 19:37:19 | 2022-10-30 19:37:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define LL long long
const int mx = 1e6;
map<char,int>mp;
char arr[100];
string A1, A2;
string B1, B2;
void init()
{
char ch = '2';
for(int i = 2; i <= 9; i++)
{
mp[ch] = i;
arr[i] = ch;
ch++;
}
mp['A'] = 1;
arr[1] = 'A';
mp['T'] = 10;
arr[10] = 'T';
mp['J'] = 11;
arr[11] = 'J';
mp['Q'] = 12;
arr[12] = 'Q';
mp['K'] = 13;
arr[13] = 'K';
}
bool cmp(string a, string b)
{
return mp[a[0]] > mp[b[0]];
}
bool is_royal_flush(vector <string> v)
{
for(int i = 1 ; i < 5; i++)
{
if(v[0][1] != v[i][1])
return false;
}
if(v[0][0] != 'K')
return false;
if(v[1][0] != 'Q')
return false;
if(v[2][0] != 'J')
return false;
if(v[3][0] != 'T')
return false;
if(v[4][0] != 'A')
return false;
return true;
}
bool is_straight_flush(vector <string> v)
{
for(int i = 1 ; i < 5; i++)
{
if(v[0][1] != v[i][1])
return false;
}
for(int i = 1; i < 5; i++)
{
if((mp[v[i - 1][0]] - mp[v[i][0]]) != 1)
return false;
}
return true;
}
bool is_four_of_a_kind(vector<string>v)
{
map<char,int>tmp;
for(auto x : v)
{
tmp[x[0]]++;
}
if(tmp.size()!= 2)
return false;
for(auto x : tmp)
{
if(x.second != 1 && x.second != 4)
return false;
}
return true;
}
bool is_full_house(vector<string>v)
{
map<char,int>tmp;
for(auto x : v)
{
tmp[x[0]]++;
}
if(tmp.size()!= 2)
return false;
for(auto x : tmp)
{
if(x.second != 2 && x.second != 3)
return false;
}
return true;
}
bool is_flush(vector <string> v)
{
for(int i = 1 ; i < 5; i++)
{
if(v[0][1] != v[i][1])
return false;
}
return true;
}
bool is_straight(vector <string> v)
{
for(int i = 1; i < 5; i++)
{
if((mp[v[i - 1][0]] - mp[v[i][0]]) != 1)
return false;
}
return true;
}
bool is_three_of_a_kind(vector<string>v)
{
map<char,int>tmp;
for(auto x : v)
{
tmp[x[0]]++;
}
if((int)tmp.size() != 3)
return false;
for(auto x : tmp)
{
if(x.second == 3)
return true;
}
return false;
}
bool is_two_pair(vector<string>v)
{
map<char,int>tmp;
for(auto x : v)
{
tmp[x[0]]++;
}
int c = 0;
for(auto x : tmp)
{
if(x.second == 2)
c++;
}
if(c == 2)
return true;
return false;
}
bool is_pair(vector<string>v)
{
map<char,int>tmp;
for(auto x : v)
{
tmp[x[0]]++;
}
int c = 0;
for(auto x : tmp)
{
if(x.second == 2)
c++;
}
if(c == 1)
return true;
return false;
}
int rankk(vector <string> v)
{
sort(v.begin(), v.end(),cmp);
if(is_royal_flush(v))
{
return 10;
}
if(is_straight_flush(v))
{
return 9;
}
if(is_four_of_a_kind(v))
return 8;
if(is_full_house(v))
return 7;
if(is_flush(v))
return 6;
if(is_straight(v))
return 5;
if(is_three_of_a_kind(v))
return 4;
if(is_two_pair(v))
return 3;
if(is_pair(v))
return 2;
return 1;
}
vector<string> deck;
int vis[10];
int fun(int pos , vector<string> alice, vector<string> bob , int player)
{
if(pos == 6)
{
sort(alice.begin(),alice.end(),cmp);
sort(bob.begin(),bob.end(),cmp);
int rank_alice = rankk(alice);
int rank_bob = rankk(bob);
if(rank_alice > rank_bob)
return 1;
if(rank_alice < rank_bob)
return 2;
for(int i = 0 ; i < 5; i++)
{
if(alice[i][0] == bob[i][0])
continue;
int a = mp[alice[i][0]];
int b = mp[bob[i][0]];
if(a > b)
return 1;
if(b > a)
return 2;
}
return 0;
}
if(player == 1){
int draw = 0;
for(int i = 0 ; i < 6; i++)
{
if(vis[i] == 0)
{
vis[i] = 1;
alice.push_back(deck[i]);
int x = fun(pos + 1, alice, bob, 2);
vis[i] = 0;
alice.pop_back();
if(x == 1)
return 1;
if(x == 0)
draw++;
}
}
if(draw > 0)
return 0;
return 2;
}
else
{
int draw = 0;
for(int i = 0 ; i < 6; i++)
{
if(vis[i] == 0)
{
vis[i] = 1;
bob.push_back(deck[i]);
int x = fun(pos + 1, alice, bob, 1);
vis[i] = 0;
bob.pop_back();
if(x == 2)
return 2;
if(x == 0)
draw++;
}
}
if(draw > 0)
return 0;
return 1;
}
}
void solve(int cs)
{
cin >> A1 >> A2;
cin >> B1 >> B2;
string str;
deck.clear();
for(int i = 0 ; i < 6; i++)
{
cin >> str;
deck.push_back(str);
}
vector<string > alice, bob;
alice.push_back(A1);
alice.push_back(A2);
bob.push_back(B1);
bob.push_back(B2);
int x = fun(0, alice,bob,1);
if(x == 1)
{
cout << "Alice" << endl;
}
else if( x == 2)
{
cout << "Bob" << endl;
}
else
cout << "Draw" << endl;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;cin>>t;
for(int cs=1;cs<=t;cs++){
solve(cs);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 3588kb
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: 5ms
memory: 3576kb
input:
1 AS 2H 2S 6H 3S 3H 4S 4H 5S 5H
output:
Draw
result:
wrong answer 1st lines differ - expected: 'Bob', found: 'Draw'