QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#118545 | #4858. Poker Game: Decision | Antonn_114 | Compile Error | / | / | C++17 | 19.1kb | 2023-07-03 17:08:23 | 2023-07-03 17:08:24 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-07-03 17:08:24]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-07-03 17:08:23]
- 提交
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;
}
#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'};
unordered_map<unsigned char, int> rank_dict{
{'A', 13},
{'K', 12},
{'Q', 11},
{'J', 10},
{'T', 9},
{'9', 8},
{'8', 7},
{'7', 6},
{'6', 5},
{'5', 4},
{'4', 3},
{'3', 2},
{'2', 1}
};
unordered_map<unsigned char, int> flush_dict{{'A', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'T', 10}, {'J', 11}, {'Q', 12}, {'K', 13}};
multiset<int> ranks;
set<int> ranks_s;
/*
inline pair<int, vector<unsigned char>> eval(vector<Card> &hand){
ranks.clear();
ranks_s.clear();
bool same_suit = true;
bool royal = true;
bool straight = true;
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, {'T', 'J', 'Q', 'K', 'A'}};
if (ranks_s.size() == 5){
vector<unsigned char> r1;
for (auto it : ranks_s) r1.push_back(it);
sort(r1.begin(), r1.end(), [&](const unsigned char& lhs, const unsigned char&rhs){
return flush_dict[lhs] > flush_dict[rhs];
});
for (int i = 0; i < 4; i++){
if (flush_dict[r1[i]] != flush_dict[r1[i + 1]] + 1) straight = false;
}
if (same_suit && straight) return {9, r1};
if (straight) return {5, r1};
sort(r1.begin(), r1.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
return rank_dict[lhs] > rank_dict[rhs];
});
return {1, r1};
}
vector<unsigned char> r2;
for (auto it : ranks){
r2.push_back(it);
}
sort(r2.begin(), r2.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
if (ranks.count(lhs) == ranks.count(rhs)) return rank_dict[lhs] > rank_dict[rhs];
return ranks.count(lhs) > ranks.count(rhs);
});
if (ranks_s.size() == 2 && (ranks.count(*ranks_s.begin()) == 1 || ranks.count(*ranks_s.begin()) == 4)) return {8, r2};
if (ranks_s.size() == 2) return {7, r2};
if (ranks_s.size() == 5 && same_suit) return {6, r2};
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, r2};
if (ranks_s.size() == 3) return {3, r2};
return {2, r2};
}*/
inline pair<int, vector<unsigned char>> eval(vector<Card> &hand){
ranks.clear();
ranks_s.clear();
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, {'T', 'J', 'Q', 'K', 'A'}};
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;
}
}
vector<unsigned char> r2;
for (auto it = ranks.rbegin(); it != ranks.rend(); it++){
r2.push_back(*it);
}
sort(r2.begin(), r2.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
if (straight)
return flush_dict[lhs] > flush_dict[rhs];
if (ranks.count(lhs) == ranks.count(rhs)) return rank_dict[lhs] > rank_dict[rhs];
return ranks.count(lhs) > ranks.count(rhs);
});
if (same_suit && straight) return {9, r2};
if (ranks_s.size() == 2 && (ranks.count(*ranks_s.begin()) == 1 || ranks.count(*ranks_s.begin()) == 4)) return {8, r2};
if (ranks_s.size() == 2) return {7, r2};
if (ranks_s.size() == 5 && same_suit) return {6, r2};
if (straight || royal) return {5, r2};
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, r2};
if (ranks_s.size() == 3) return {3, r2};
if (ranks_s.size() == 4) return {2, r2};
return {1, r2};
}
vector<Card> Alice, Bob, Common;
int dp[64];
int main() {
// Try to avoid cin, cout :)
int tc = 1; cin >> tc;
while(tc--) {
/// Your solution here
string s;
Alice.clear();
Bob.clear();
Common.clear();
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 tmp1= 0, tmp2=0, tmp3 =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]);
}
auto score_a = eval(Alice);
auto score_b = eval(Bob);
int winner = 0;
/*
for (auto it : Alice) cout << it.rank << it.suit << " ";
cout << " -> A = " << score_a.first << endl;
for (auto it : Bob) cout << it.rank << it.suit << " ";
cout << " -> B = " << score_b.first << endl;
*/
if (score_a.first > score_b.first) winner = 1;
else if (score_b.first > score_a.first) winner = -1;
else{
for (int jj = 0; jj < 5; jj++){
if (score_a.second[jj]!= score_b.second[jj]){
if (rank_dict[score_a.second[jj]] > rank_dict[score_b.second[jj]])
winner = 1;
else
winner = -1;
break;
}
}
}
//cout << "WINNER " << (winner == 1 ? "A" : winner == 0 ? "DRAW" : "B") << endl;
dp[(1 << i) | (1 << j) | (1 << k)] = winner;
if (winner == 1) tmp1++;
if (winner == -1) tmp2++;
if (winner == 0) tmp3++;
Bob.pop_back(); Bob.pop_back(); Bob.pop_back();
Alice.pop_back();
}
Alice.pop_back();
}
Alice.pop_back();
}
//cout << tmp1 << " " << tmp2 << " " << tmp3 << endl;
int winwin_a = 0, winwin_b = 0, windraw = 0;
for (int i = 0; i < 6; i++){
int a_win_a = 0, a_win_b = 0, a_draw = 0;
for (int j = 0; j < 6; j++){
if (i == j) continue;
int b_win_a = 0, b_win_b = 0, b_draw = 0;
for (int k = 0; k < 6; k++){
if (k == j || k == i) continue;
int win_a = 0, win_b= 0, draw = 0;
for (int l = 0; l < 6; l++){
if (l == j || l == i || l == k) continue;
int ss = dp[(1 << i) | (1 << k) | (1 << l)];
if (ss == 1) win_a++;
else if (ss == -1) win_b++;
else draw++;
}
if (win_a >= 2) b_win_a++;
else if (draw >= 2) b_draw++;
else if (win_b >= 2) b_win_b++;
else b_draw++;
}
if (b_win_a) a_win_a++;
else if (b_draw) a_draw++;
else a_win_b++;
}
if (a_win_b) winwin_b++;
else if (a_draw) windraw++;
else winwin_a++;
}
//cout << winwin_a << " " << winwin_b << " " << windraw << endl;
if (winwin_a) cout << "Alice\n";
else if (windraw) cout << "Draw\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
*
**/
};
const unsigned char flush_order[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
unordered_map<unsigned char, int> rank_dict{
{'A', 13},
{'K', 12},
{'Q', 11},
{'J', 10},
{'T', 9},
{'9', 8},
{'8', 7},
{'7', 6},
{'6', 5},
{'5', 4},
{'4', 3},
{'3', 2},
{'2', 1}
};
unordered_map<unsigned char, int> flush_dict{{'A', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'T', 10}, {'J', 11}, {'Q', 12}, {'K', 13}};
multiset<int> ranks;
set<int> ranks_s;
/*
inline pair<int, vector<unsigned char>> eval(vector<Card> &hand){
ranks.clear();
ranks_s.clear();
bool same_suit = true;
bool royal = true;
bool straight = true;
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, {'T', 'J', 'Q', 'K', 'A'}};
if (ranks_s.size() == 5){
vector<unsigned char> r1;
for (auto it : ranks_s) r1.push_back(it);
sort(r1.begin(), r1.end(), [&](const unsigned char& lhs, const unsigned char&rhs){
return flush_dict[lhs] > flush_dict[rhs];
});
for (int i = 0; i < 4; i++){
if (flush_dict[r1[i]] != flush_dict[r1[i + 1]] + 1) straight = false;
}
if (same_suit && straight) return {9, r1};
if (straight) return {5, r1};
sort(r1.begin(), r1.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
return rank_dict[lhs] > rank_dict[rhs];
});
return {1, r1};
}
vector<unsigned char> r2;
for (auto it : ranks){
r2.push_back(it);
}
sort(r2.begin(), r2.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
if (ranks.count(lhs) == ranks.count(rhs)) return rank_dict[lhs] > rank_dict[rhs];
return ranks.count(lhs) > ranks.count(rhs);
});
if (ranks_s.size() == 2 && (ranks.count(*ranks_s.begin()) == 1 || ranks.count(*ranks_s.begin()) == 4)) return {8, r2};
if (ranks_s.size() == 2) return {7, r2};
if (ranks_s.size() == 5 && same_suit) return {6, r2};
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, r2};
if (ranks_s.size() == 3) return {3, r2};
return {2, r2};
}*/
inline pair<int, vector<unsigned char>> eval(vector<Card> &hand){
ranks.clear();
ranks_s.clear();
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, {'T', 'J', 'Q', 'K', 'A'}};
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;
}
}
vector<unsigned char> r2;
for (auto it = ranks.rbegin(); it != ranks.rend(); it++){
r2.push_back(*it);
}
sort(r2.begin(), r2.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
if (straight)
return flush_dict[lhs] > flush_dict[rhs];
if (ranks.count(lhs) == ranks.count(rhs)) return rank_dict[lhs] > rank_dict[rhs];
return ranks.count(lhs) > ranks.count(rhs);
});
if (same_suit && straight) return {9, r2};
if (ranks_s.size() == 2 && (ranks.count(*ranks_s.begin()) == 1 || ranks.count(*ranks_s.begin()) == 4)) return {8, r2};
if (ranks_s.size() == 2) return {7, r2};
if (ranks_s.size() == 5 && same_suit) return {6, r2};
if (straight || royal) return {5, r2};
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, r2};
if (ranks_s.size() == 3) return {3, r2};
if (ranks_s.size() == 4) return {2, r2};
return {1, r2};
}
vector<Card> Alice, Bob, Common;
int dp[64];
int main() {
// Try to avoid cin, cout :)
int tc = 1; cin >> tc;
while(tc--) {
/// Your solution here
memset(dp, 0, sizeof dp);
string s;
Alice.clear();
Bob.clear();
Common.clear();
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 tmp1= 0, tmp2=0, tmp3 =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]);
}
auto score_a = eval(Alice);
auto score_b = eval(Bob);
int winner = 0;
/*
for (auto it : Alice) cout << it.rank << it.suit << " ";
cout << " -> A = " << score_a.first << endl;
for (auto it : Bob) cout << it.rank << it.suit << " ";
cout << " -> B = " << score_b.first << endl;
*/
if (score_a.first > score_b.first) winner = 1;
else if (score_b.first > score_a.first) winner = -1;
else{
for (int jj = 0; jj < 5; jj++){
if (score_a.second[jj]!= score_b.second[jj]){
if (rank_dict[score_a.second[jj]] > rank_dict[score_b.second[jj]])
winner = 1;
else
winner = -1;
break;
}
}
}
//cout << "WINNER " << (winner == 1 ? "A" : winner == 0 ? "DRAW" : "B") << endl;
dp[(1 << i) | (1 << j) | (1 << k)] = winner;
if (winner == 1) tmp1++;
if (winner == -1) tmp2++;
if (winner == 0) tmp3++;
Bob.pop_back(); Bob.pop_back(); Bob.pop_back();
Alice.pop_back();
}
Alice.pop_back();
}
Alice.pop_back();
}
//cout << tmp1 << " " << tmp2 << " " << tmp3 << endl;
int winwin_a = 0, winwin_b = 0, windraw = 0;
for (int i = 0; i < 6; i++){
int a_win_a = 0, a_win_b = 0, a_draw = 0;
for (int j = 0; j < 6; j++){
if (i == j) continue;
int b_win_a = 0, b_win_b = 0, b_draw = 0;
for (int k = 0; k < 6; k++){
if (k == j || k == i) continue;
int win_a = 0, win_b= 0, draw = 0;
for (int l = 0; l < 6; l++){
if (l == j || l == i || l == k) continue;
int ss = dp[(1 << i) | (1 << k) | (1 << l)];
if (ss == 1) win_a++;
else if (ss == -1) win_b++;
else draw++;
}
if (win_a >= 2) b_win_a++;
else if (draw >= 2) b_draw++;
else if (win_b >= 2) b_win_b++;
else b_draw++;
}
if (b_win_a) a_win_a++;
else if (b_draw) a_draw++;
else a_win_b++;
}
if (a_win_b) winwin_b++;
else if (a_draw) windraw++;
else winwin_a++;
}
//cout << winwin_a << " " << winwin_b << " " << windraw << endl;
if (winwin_a) cout << "Alice\n";
else if (windraw) cout << "Draw\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
*
**/
詳細信息
answer.code:14:7: error: expected nested-name-specifier before ‘namespace’ 14 | using namespace std; | ^~~~~~~~~ answer.code:18:8: error: ‘Card::Card’ has the same name as the class in which it is declared 18 | struct Card{ | ^~~~ answer.code:27:21: error: flexible array member ‘Card::flush_order’ not at end of ‘struct Card’ 27 | const unsigned char flush_order[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'}; | ^~~~~~~~~~~ answer.code:27:21: error: initializer for flexible array member ‘const unsigned char Card::flush_order []’ answer.code: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Card; _Args = {const Card&}; _Tp = Card]’: /usr/include/c++/11/bits/alloc_traits.h:512:17: required from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Card; _Args = {const Card&}; _Tp = Card; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<Card>]’ /usr/include/c++/11/bits/stl_vector.h:1192:30: required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Card; _Alloc = std::allocator<Card>; std::vector<_Tp, _Alloc>::value_type = Card]’ answer.code:177:28: required from here answer.code:27:21: error: initializer for flexible array member ‘const unsigned char Card::flush_order []’ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/c++allocator.h:33, from /usr/include/c++/11/bits/allocator.h:46, from /usr/include/c++/11/string:41, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/ext/new_allocator.h:156:11: note: synthesized method ‘Card::Card(const Card&)’ first required here 156 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ answer.code: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Card; _Args = {Card}; _Tp = Card]’: /usr/include/c++/11/bits/alloc_traits.h:512:17: required from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Card; _Args = {Card}; _Tp = Card; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<Card>]’ /usr/include/c++/11/bits/vector.tcc:115:30: required from ‘std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {Card}; _Tp = Card; _Alloc = std::allocator<Card>; std::vector<_Tp, _Alloc>::reference = Card&]’ /usr/include/c++/11/bits/stl_vector.h:1204:21: required from ‘void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = Card; _Alloc = std::allocator<Card>; std::vector<_Tp, _Alloc>::value_type = Card]’ answer.code:167:38: required from here answer.code:27:21: error: initializer for flexible array member ‘const unsigned char Card::flush_order []’ 27 | const unsigned char flush_order[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'}; | ^~~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/c++allocator.h:33, from /usr/include/c++/11/bits/allocator.h:46, from /usr/include/c++/11/string:41, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/ext/new_allocator.h:156:11: note: synthesized method ‘Card::Card(Card&&)’ first required here 156 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~