QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#59553 | #4858. Poker Game: Decision | captured | TL | 4ms | 3668kb | C++14 | 9.1kb | 2022-10-31 00:29:44 | 2022-10-31 00:29:46 |
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++)
{
// cout << ch << " = " << i << endl;
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;
}
///
/*
1
AS AH
AC AD
2H 3S 4D 5C 6H 7S
AS AH
AC AD
2C 2D 3S 3H 4C 4D
*/
///
vector<string> deck;
int vis[10];
char straight_arr[5] = {'A', '5' , '4' , '3', '2'};
int k_jitlo[(1<<6) + 10];
int khela(vector<string>alice, vector<string>bob)
{
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());
}
}
///
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());
}
}
///
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;
}
void preq(int mask, int pos)
{
if(__builtin_popcount(mask) == 3)
{
// cout << "mask " << mask << " = "<< __builtin_popcount(mask) << endl;
vector<string>alice,bob;
alice.push_back(A1);
alice.push_back(A2);
bob.push_back(B1);
bob.push_back(B2);
for(int i = 0; i < 6; i++)
{
if(mask & (1<<i))
{
alice.push_back(deck[i]);
}
else
bob.push_back(deck[i]);
}
k_jitlo[mask] = khela(alice, bob);
return;
}
if(pos == 6)
return;
preq(mask | (1<<pos) , pos + 1);
preq(mask , pos + 1);
}
int fun(int pos , int alice_mask, int player)
{
if(pos == 6)
{
return k_jitlo[alice_mask];
}
if(player == 1){
int draw = 0;
for(int i = 0 ; i < 6; i++)
{
if(vis[i] == 0)
{
vis[i] = 1;
int x = fun(pos + 1, alice_mask | (1<<i), 2);
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;
int x = fun(pos + 1, alice_mask, 1);
vis[i] = 0;
if(x == 2)
return 2;
if(x == 0)
draw++;
}
}
if(draw > 0)
return 0;
return 1;
}
}
void solve(int cs)
{
memset(k_jitlo, -1, sizeof k_jitlo);
cin >> A1 >> A2;
cin >> B1 >> B2;
string str;
deck.clear();
for(int i = 0 ; i < 6; i++)
{
cin >> str;
deck.push_back(str);
}
preq(0,0);
int x = fun(0, 0,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;
init();
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: 4ms
memory: 3668kb
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: 2ms
memory: 3504kb
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: 2ms
memory: 3624kb
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 Bob 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 Bob Alice Alice Alice Alice Alice Alice ...