QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#601335 | #7061. Poker Game | tkt0506 | RE | 0ms | 3668kb | C++14 | 9.3kb | 2024-09-29 22:24:21 | 2024-09-29 22:24:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int suit(int a){
return (a-1)/13;
}
int Rank(int a){
if(a%13 == 1)return 13;
else return (a-1)%13;
}
// Detect values
int isPair(vector<int>hand, vector<int>comm){ // same pair?
vector<int>cnt(14,0);
for(int e : hand)cnt[Rank(e)]++;
for(int e : comm)cnt[Rank(e)]++;
for(int i=13; i>=0; i--)if(cnt[i]>=2)return i;
return 0;
}
int isThree(vector<int>hand, vector<int>comm){
vector<int>cnt(14,0);
for(int e : hand)cnt[Rank(e)]++;
for(int e : comm)cnt[Rank(e)]++;
for(int i=13; i>=0; i--)if(cnt[i]>=3)return i;
return 0;
}
int isFlush(vector<int>hand, vector<int>comm){
vector<int>cnt(4,0);
for(int e : hand)cnt[suit(e)]++;
for(int e : comm)cnt[suit(e)]++;
int mx = 0;
for(int i=0; i<4; i++){
if(cnt[i]>=5){
for(int e : hand)if(suit(e)==i)mx = max(mx, Rank(e));
for(int e : comm)if(suit(e)==i)mx = max(mx, Rank(e));
}
}
return mx;
}
int isStraight(vector<int>hand, vector<int>comm){
vector<int>cnt(14,0);
for(int e : hand)cnt[Rank(e)]++;
for(int e : comm)cnt[Rank(e)]++;
int mx = 0;
for(int i=1; i+4<=13; i++){
bool flag = cnt[i];
for(int j=i+1; j<=i+4; j++)flag &= cnt[j];
if(flag)mx = max(mx, i+4);
}
if(cnt[13] && cnt[1] && cnt[2] && cnt[3] && cnt[4])mx = max(mx, 4);
return mx;
}
int isStraightFlush(vector<int>hand, vector<int>comm){
vector<int>cnt(54,0);
for(int e : hand)cnt[e]++;
for(int e : comm)cnt[e]++;
int mx = 0;
for(int i=0; i<4; i++){
vector<int>tmp;
for(int j=i*13+1; j<=(i+1)*13; j++)if(cnt[j])tmp.push_back(j);
if(isStraight(tmp,{}))mx = 13;
}
return mx;
}
int needFlush(vector<int>hand, vector<int>comm, vector<int>hole){
vector<int>cnt(4,0), cnt2(4,0);
for(int e : hand)cnt[suit(e)]++;
for(int e : comm)cnt[suit(e)]++;
for(int e : hole)cnt2[suit(e)]++;
int mx = 5;
for(int i=0; i<4; i++)if(5-cnt[i]<=13-cnt2[i]-cnt[i])mx = min(mx, 5-cnt[i]);
return mx;
}
int needStraight(vector<int>hand, vector<int>comm, vector<int>hole){
vector<int>cnt(14,0), cnt2(14,0);
for(int e : hand)cnt[Rank(e)]++;
for(int e : comm)cnt[Rank(e)]++;
for(int e : hole)cnt2[Rank(e)]++;
int mx = 5;
for(int i=1; i+4<=13; i++){
int tot = 0;
if(cnt[i])tot++;
for(int j=i+1; j<=i+4; j++)if(cnt[j])tot++;
bool flag = 1;
for(int j=i; j<=i+1; j++){
if(!cnt[j] && cnt2[j]==4)flag = 0;
}
if(!flag)continue;
mx = min(mx, 5-tot);
}
int tot = 0;
bool flag = 1;
for(int j=1; j<=4; j++)if(!cnt[j] && cnt2[j]==4)flag = 0;
if(!cnt[13] && cnt2[13] == 4)flag = 0;
if(cnt[13])tot++;
if(cnt[1])tot++;
if(cnt[2])tot++;
if(cnt[3])tot++;
if(cnt[4])tot++;
if(flag)mx = min(mx, 5-tot);
return mx;
}
// Strategy 1
int playA(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round){
if(round == 1){
if(pot < 15 || (suit(hand[0]) != suit(hand[1])))return 0;
return min(pot,5);
}
if(round == 2){
return min(pot,5);
// if(isPair(hand, comm) || needFlush(hand, comm, hole) <= 2|| needStraight(hand, comm, hole) <= 2)return min(pot, 5);
// return 0;
}
if(round == 3 || round == 2){
if(isPair(hand, comm) || isThree(hand, comm) || isFlush(hand, comm) || isStraight(hand,comm) || isStraightFlush(hand,comm))return min(pot, 5);
return 0;
}
}
// Strategy 2
int playB(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round){
if(round == 1){
if(pot >= 15 || (Rank(hand[0]) == 13 && Rank(hand[1]) == 13))return min(pot,5);
return 0;
}
if(round == 2){
if(isPair(hand, comm) || isThree(hand, comm) || isFlush(hand, comm) || isStraight(hand,comm) || isStraightFlush(hand,comm))return min(pot, 5);
if(needFlush(hand, comm, hole) == 1 || needStraight(hand,comm, hole) == 1)return min(pot, 5);
return 0;
}
if(round == 3){
vector<int>cnt(4,0);
for(int e : comm)cnt[suit(e)]++;
for(int i=0; i<4; i++)if(cnt[i] >= 4)return 0;
return min(pot, 5);
}
}
// Strategy 3
int playC(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round){
if(round == 1){
if(Rank(hand[0]) == 13 || Rank(hand[1]) == 13 || abs(Rank(hand[0])-Rank(hand[1])) < 3)return min(pot, 5);
return 0;
}
if(round ==2){
vector<int>cnt(14,0);
for(int e : comm)cnt[Rank(e)]++;
for(int i=1; i<=13; i++){
if(cnt[i] >= 2){
bool flag = 0;
for(int e : hand)if(Rank(e) == i)flag = 1;
if(!flag)return 0;
}
}
return min(pot,5);
}
if(round == 3)return min(pot, 5);
}
// Strategy 4
int playD(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round){
if(round == 1){
for(int e : hand)if(Rank(e) > 10)return min(pot, 5);
return 0;
}
if(round == 2){
int mx = 0;
for(int e : hand)mx = max(mx, Rank(e));
int mx2 = 0;
for(int e : comm)mx2 = max(mx2, Rank(e));
// cout << mx << " " << mx2 << "\n";
if(mx > mx2)return min(pot, 5);
for(int e : hand)if(Rank(e) == mx2)return min(pot,5);
return 0;
}
if(round == 3){
if(isThree(hand, comm) || isFlush(hand, comm) || isStraight(hand,comm) || isStraightFlush(hand,comm))return min(pot, 5);
vector<int>tmp;
for(int e : comm)tmp.push_back(Rank(e));
sort(tmp.begin(), tmp.end());
if(isPair(hand, comm) > tmp[2])return min(pot, 5);
return 0;
}
}
// Strategy 5
int playE(int pot, vector<int>hand, vector<int>comm, vector<int>hole, int round, int ppl){
if(round == 1){
if(ppl==2)return min(pot, 5);
else return 0;
}
return min(pot,5);
}
vector<bool>isFold(5,0), isAllin(5,0);
vector<int>coin(5,100);
vector<int>Hand[5], Comm;
int Ppl = 5, win = 0;
void play(int a, int r){
if(isFold[a])return ;
int v;
if(a==0)v = playA(coin[0], Hand[0], Comm, {},r);
else if(a==1)v = playB(coin[1], Hand[1], Comm, {},r);
else if(a==2)v = playC(coin[2], Hand[2], Comm, {},r);
else if(a==3)v = playD(coin[3], Hand[3], Comm, {},r);
else v = playE(coin[4], Hand[4], Comm, {},r, Ppl);
win += v;
// cout << "PLAY: " << a << " " << v << "\n";
coin[a] -= v;
if(v==0){
isFold[a] = 1;
Ppl--;
}else{
if(coin[a] == 0)isAllin[a] = 1;
}
}
typedef pair<int,int> pii;
pii calc(int a){
if(isStraightFlush(Hand[a],Comm))return {6,isStraightFlush(Hand[a],Comm)};
if(isFlush(Hand[a],Comm))return {5,isFlush(Hand[a],Comm)};
if(isStraight(Hand[a],Comm))return {4,isStraight(Hand[a],Comm)};
if(isThree(Hand[a],Comm))return {3,isThree(Hand[a],Comm)};
if(isPair(Hand[a],Comm))return {2,isPair(Hand[a],Comm)};
int mx = 0;
for(int e : Hand[a])mx = max(mx, Rank(e));
return {1,mx};
}
int main(){
int n;
cin >> n;
while(n--){
// for(int e : coin)cout << e << ' ';
// cout << "\n";
// cout << "\nNEW ROUND\n";
Comm.clear();
Ppl = 5;
win = 0;
for(int i=0; i<5; i++){
Hand[i].clear();
isFold[i] = isAllin[i] = 0;
}
vector<int>a(15);
for(int i=0; i<15; i++)cin >> a[i];
// for(int i=0; i<15; i++)cout << Rank(a[i])+1 << " " << suit(a[i]) << "\n";
// cout << "\n";
int idx = 0;
for(int i=0; i<5; i++){
if(!coin[i])continue;
Hand[i].push_back(a[idx]);
Hand[i].push_back(a[idx+1]);
idx += 2;
}
// round 1
for(int i=0; i<4; i++)play(i,1);
if(Ppl == 1){
coin[4] += win;
continue;
}else play(4,1);
// round 2
Comm.push_back(a[idx]);
Comm.push_back(a[idx+1]);
Comm.push_back(a[idx+2]);
idx += 3;
bool endFlag = 0;
for(int i=0; i<5; i++){
if(Ppl == 1 && !isFold[i]){
coin[i] += win;
endFlag = 1;
break;
}
play(i,2);
}
if(endFlag)continue;
// round 3
Comm.push_back(a[idx]);
Comm.push_back(a[idx+1]);
for(int i=0; i<5; i++){
if(Ppl == 1 && !isFold[i]){
coin[i] += win;
endFlag = 1;
break;
}
play(i,3);
}
if(endFlag)continue;
// final battle
int idx2 = -1, scr = 0, scr2 = 0;
for(int i=0; i<5; i++){
if(isFold[i])continue;
pii res = calc(i);
if(idx == -1 || res.first > scr || (res.first == scr && res.second >= scr2)){
idx2 = i;
scr = res.first;
scr2 = res.second;
}
}
// cout << "WIN: " << idx2 << "\n";
coin[idx2] += win;
}
for(int e : coin)cout << e << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
2 1 2 8 10 3 11 15 12 14 27 42 43 45 48 13 14 2 8 10 3 11 5 23 1 27 42 43 13 45 48
output:
90 90 100 115 105
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
5 9 5 19 35 30 42 18 8 21 51 16 26 32 29 49 17 50 13 7 37 21 25 31 28 18 30 27 24 16 15 31 38 52 46 1 29 41 12 39 24 10 45 13 22 42 8 10 33 18 39 49 29 43 51 2 35 19 27 41 12 48 13 33 39 30 47 32 24 12 9 42 1 18 41 51
output:
65 115 115 100 105
result:
ok 5 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
5 51 31 17 50 24 15 25 20 22 16 44 6 19 39 28 34 1 21 10 31 15 35 8 27 51 32 23 48 24 29 39 18 27 14 31 2 35 51 44 21 24 6 43 16 19 9 44 4 19 35 47 15 51 25 20 40 8 21 6 7 49 35 11 12 44 29 22 9 16 13 4 17 32 25 7
output:
100 125 115 75 85
result:
ok 5 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
5 16 41 30 6 5 39 22 1 29 42 32 49 40 27 21 39 14 32 48 6 37 23 35 13 52 43 2 24 38 45 49 42 38 18 47 52 30 15 16 1 26 31 28 6 40 47 31 22 45 49 46 36 17 35 48 38 33 13 16 20 41 17 9 34 25 21 8 18 22 24 4 20 26 15 42
output:
90 80 100 115 115
result:
ok 5 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
5 26 38 46 4 52 15 51 7 1 30 5 3 33 47 34 22 7 15 9 5 29 32 23 30 25 33 2 1 50 4 22 44 31 33 32 39 26 5 21 15 48 2 52 37 13 21 50 12 7 43 26 32 28 42 30 20 9 35 47 8 38 12 4 33 10 25 50 37 46 36 6 40 29 48 5
output:
100 65 100 120 115
result:
ok 5 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
5 32 51 43 23 30 17 36 37 48 22 46 41 20 1 42 49 29 40 4 19 46 13 39 8 12 47 38 16 32 34 37 34 45 36 10 26 33 21 46 35 39 13 41 27 19 51 15 42 35 27 52 18 1 44 37 26 39 33 32 8 31 50 52 24 37 17 26 2 20 13 1 38 9 49 51
output:
85 105 110 100 100
result:
ok 5 lines
Test #7:
score: -100
Runtime Error
input:
50 13 27 25 40 35 8 4 48 24 21 23 41 28 34 46 17 24 35 47 44 39 23 51 41 26 9 8 11 25 6 46 2 15 10 45 1 32 29 4 47 14 35 49 16 22 30 43 11 47 42 28 17 39 18 15 24 5 22 12 7 7 32 43 36 17 3 1 12 34 27 35 16 29 22 45 42 38 8 45 37 22 50 33 31 49 28 20 17 40 15 17 10 30 39 18 48 32 4 26 13 27 22 3 2 8 ...