QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#59541 | #4858. Poker Game: Decision | captured# | WA | 10ms | 3632kb | C++14 | 8.4kb | 2022-10-30 21:32:17 | 2022-10-30 21:32:18 |
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()
{
mp['a'] = 1;
char ch = '2';
for(int i = 2; i <= 9; i++)
{
mp[ch] = i;
arr[i] = ch;
ch++;
}
mp['A'] = 14;
arr[14] = '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] != 'A')
return false;
if(v[1][0] != 'K')
return false;
if(v[2][0] != 'Q')
return false;
if(v[3][0] != 'J')
return false;
if(v[4][0] != 'T')
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(((int)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(((int)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 c2 = 0 , c1 = 0;
for(auto x : tmp)
{
if(x.second == 2)
c2++;
if(x.second == 1)
c1++;
}
if(c2 == 1 && c1 == 3)
return true;
return false;
}
bool is_highcard(vector<string>v)
{
map<char,int>tmp;
for(auto x : v)
{
tmp[x[0]]++;
}
int c2 = 0 , c1 = 0;
for(auto x : tmp)
{
if(x.second == 1)
c1++;
}
if( c1 == 5)
return true;
return false;
}
int rankk(vector <string> v)
{
if(v.size() > 5)
assert(0);
sort(v.begin(), v.end(),cmp);
vector<string> tmp_v = v;
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;
if(is_highcard(v))
return 1;
// cout << " ok " << endl;
assert(0);
return 0;
}
vector<string> deck;
int vis[10];
char straight_arr[5] = {'A', '5' , '4' , '3', '2'};
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);
int al_st = 0;
int f = 1;
for(int i = 0 ; i < 5; i++)
{
if(alice[i][0] != straight_arr[i])
f = 0;
}
if(f)
{
if(rank_alice < 5)
{
rank_alice = 5;
alice[0][0] = 'a';
for(int i = 1 , j = 4; i < j;i++,j--)
{
swap(alice[i],alice[j]);
}
reverse(alice.begin(),alice.end());
}
else if(rank_alice == 6)
{
rank_alice = 9;
alice[0][0] = 'a';
for(int i = 1 , j = 4; i < j;i++,j--)
{
swap(alice[i],alice[j]);
}
reverse(alice.begin(),alice.end());
}
else
{
assert(0);
}
}
///
f = 1;
for(int i = 0 ; i < 5; i++)
{
if(bob[i][0] != straight_arr[i])
f = 0;
}
if(f)
{
if(rank_bob < 5)
{
rank_bob = 5;
bob[0][0] = 'a';
for(int i = 1 , j = 4; i < j;i++,j--)
{
swap(bob[i],bob[j]);
}
reverse(bob.begin(), bob.end());
}
else if(rank_bob == 6)
{
rank_bob = 9;
bob[0][0] = 'a';
for(int i = 1 , j = 4; i < j;i++,j--)
{
swap(bob[i],bob[j]);
}
reverse(bob.begin(), bob.end());
}
else
assert(0);
}
///
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);
alice.pop_back();
vis[i] = 0;
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);
bob.pop_back();
vis[i] = 0;
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: 10ms
memory: 3552kb
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: 3632kb
input:
1 AS 2H 2S 6H 3S 3H 4S 4H 5S 5H
output:
Draw
result:
wrong answer 1st lines differ - expected: 'Bob', found: 'Draw'