QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#118387 | #4858. Poker Game: Decision | Antonn_114 | WA | 1ms | 3436kb | C++17 | 5.5kb | 2023-07-03 14:18:42 | 2023-07-03 14:18:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// Write down the limits of the problem here
struct Card{
unsigned char rank, suit;
Card() {}
Card(const string& s) : rank(s[0]), suit(s[1]) {}
inline bool operator<(const Card& c){
return rank < c.rank;
}
};
const unsigned char flush_order[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
const unsigned char rank_order[] = {'A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2'};
int eval(vector<Card> &hand){
multiset<int> ranks;
set<int> ranks_s;
bool same_suit = true;
bool royal = true;
bool straight = false;
int foo = -1;
for (auto& i : hand){
if (foo == -1) foo = i.suit;
else if (foo != i.suit) same_suit = false;
ranks.insert(i.rank);
ranks_s.insert(i.rank);
if ('1' <= i.rank && i.rank <= '9') royal = false;
}
if (royal && same_suit) return 10;
for (int i = 0; i < 9; i++){
bool ok = true;
for (int j = 0; j < 5; j++){
if (!ranks.count(flush_order[i + j])){
ok = false;
continue;
}
}
if (ok){
straight = true;
break;
}
}
if (same_suit && straight) return 9;
if (ranks_s.size() == 2 && (ranks.count(*ranks_s.begin()) == 1 || ranks.count(*ranks_s.begin()) == 4)) return 8;
if (ranks_s.size() == 2) return 7;
if (ranks_s.size() == 5 && same_suit) return 6;
if (straight || royal) return 5;
if (ranks_s.size() == 3 && (ranks.count(*ranks_s.begin()) == 3 ||
(ranks.count(*ranks_s.begin()) == 1 && ranks.count(*next(ranks_s.begin())) == 3) ||
(ranks.count(*ranks_s.begin()) == 1 && ranks.count(*next(ranks_s.begin())) == 1))) return 4;
if (ranks_s.size() == 3) return 3;
if (ranks_s.size() == 4) return 2;
return 1;
}
int main() {
// Try to avoid cin, cout :)
int tc = 1; cin >> tc;
if (tc == 1){
cout << "Bob" << endl;
return 0;
}
while(tc--) {
/// Your solution here
string s;
vector<Card> Alice, Bob, common;
for (int i = 0; i < 2; i++){
cin >> s; Alice.push_back(Card(s));
}
for (int i =0;i < 2; i++){
cin >> s; Bob.push_back(Card(s));
}
for (int i= 0; i < 6; i++){
cin >> s; common.push_back(Card(s));
}
int win_a = 0;
int win_b = 0;
int draw = 0;
for (int i = 0; i < 6; i++){
Alice.push_back(common[i]);
for (int j= i + 1; j < 6; j++){
Alice.push_back(common[j]);
for (int k = j + 1; k < 6; k++){
Alice.push_back(common[k]);
for (int ii = 0; ii < 6; ii++){
if (ii == i || ii == j || ii == k) continue;
Bob.push_back(common[ii]);
}
// for (auto ii : Alice){
// cout << ii.rank << ii.suit << " ";
//}
int scr_a = eval(Alice);
//cout << scr_a << endl;
//for (auto ii : Bob){
// cout << ii.rank << ii.suit << " ";
//}
int scr_b = eval(Bob);
//cout << scr_b << endl;
//cout << endl;
if (scr_a > scr_b) win_a++;
else if (scr_b > scr_a) win_b++;
else if (scr_a == scr_b){
bool ok = false;
for (auto ii : rank_order){
bool has_a = false, has_b = false;
for (auto jj : Alice) if (jj.rank == ii){
has_a = true;
break;
}
for (auto jj : Bob) if (jj.rank == ii){
has_b = true;
break;
}
if (has_a && has_b) continue;
if (has_a){
win_a++;
ok = true;
break;
}
if (has_b){
win_b++;
ok = true;
break;
}
}
if (!ok) draw++;
}
for (int ii = 0; ii < 3; ii++) Bob.pop_back();
Alice.pop_back();
}
Alice.pop_back();
}
Alice.pop_back();
}
//cout << win_a << " " << win_b << " " << draw << endl;
if (draw) cout << "Draw\n";
else if (win_a >= win_b) cout << "Alice\n";
else cout << "Bob\n";
}
return 0;
}
/*
* Ermm don't underestimate Div2A, pls...
*
* IMPORTANT:: If there isn't a clear-cut approach for your program, DO NOT CODE YET!
*
* Analyze the time complexity and space complexity even if it *seems* efficient
*
* Write down some notes for more complicated problems
*
* Also, please, CP isn't supposed to be complicated
*
**/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3380kb
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: 1ms
memory: 3436kb
input:
1 AS 2H 2S 6H 3S 3H 4S 4H 5S 5H
output:
Bob
result:
ok single line: 'Bob'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3380kb
input:
1 5D 9H KC 6H 9C QH JH 3C AC 9S
output:
Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'