cp_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub SSRS-cp/cp_library

:heavy_check_mark: test/aoj/other/2535.test.cpp

Depends on

Code

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2535"
#define ERROR 0.0000001
#include <bits/stdc++.h>
using namespace std;
#include "other/poker_hands.hpp"
vector<int> hand2(vector<card> C){
  vector<int> ans;
  vector<int> p = {0, 0, 1, 1, 1, 1, 1};
  while (true){
    array<card, 5> C2;
    int cnt = 0;
    for (int i = 0; i < 7; i++){
      if (p[i] == 1){
        C2[cnt] = C[i];
        cnt++;
      }
    }
    ans = max(ans, hand(C2));
    if (!next_permutation(p.begin(), p.end())){
      break;
    }
  }
  return ans;
}
int main(){
  cout << fixed << setprecision(20);
  while (true){
    vector<card> C(9);
    for (int i = 0; i < 7; i++){
      cin >> C[i];
    }
    if (!cin){
      break;
    }
    string suits = "SHDC";
    int cnt1 = 0, cnt2 = 0;
    for (int s1 = 0; s1 < 4; s1++){
      for (int r1 = 2; r1 <= 14; r1++){
        for (int s2 = 0; s2 < 4; s2++){
          for (int r2 = 2; r2 <= 14; r2++){
            C[7].suit = suits[s1];
            C[7].rank = r1;
            C[8].suit = suits[s2];
            C[8].rank = r2;
            bool ok = true;
            for (int i = 0; i < 9; i++){
              for (int j = i + 1; j < 9; j++){
                if (C[i].suit == C[j].suit && C[i].rank == C[j].rank){
                  ok = false;
                }
              }
            }
            if (ok){
              vector<card> A = {C[0], C[1], C[4], C[5], C[6], C[7], C[8]};
              vector<card> B = {C[2], C[3], C[4], C[5], C[6], C[7], C[8]};
              if (hand2(A) > hand2(B)){
                cnt1++;
              }
              cnt2++;
            }
          }
        }
      }
    }
    cout << (double) cnt1 / cnt2 << endl;
  }
}
#line 1 "test/aoj/other/2535.test.cpp"
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2535"
#define ERROR 0.0000001
#include <bits/stdc++.h>
using namespace std;
#line 2 "other/poker_hands.hpp"
struct card{
  char suit;
  int rank;
  card(){
  }
  bool operator <(card C){
    return rank < C.rank || rank == C.rank && suit < C.suit;
  }
};
istream& operator >>(istream& is, card& C){
  string S;
  is >> S;
  C.suit = S[0];
  if (S[1] == 'A'){
    C.rank = 14;
  } else if (S[1] == 'K'){
    C.rank = 13;
  } else if (S[1] == 'Q'){
    C.rank = 12;
  } else if (S[1] == 'J'){
    C.rank = 11;
  } else if (S[1] == 'T'){
    C.rank = 10;
  } else {
    C.rank = S[1] - '0';
  }
  return is;
}
enum poker_hand{HIGH_CARD, ONE_PAIR, TWO_PAIR, THREE_OF_A_KIND, STRAIGHT, FLUSH, FULL_HOUSE, FOUR_OF_A_KIND, STRAIGHT_FLUSH, ROYAL_STRAIGHT_FLUSH};
vector<int> hand(array<card, 5> C){
  sort(C.begin(), C.end());
  bool is_flush = true;
  for (int i = 1; i < 5; i++){
    if (C[i].suit != C[0].suit){
      is_flush = false;
    }
  }
  if (is_flush && C[4].rank == 14 && C[0].rank == 10){
    return {ROYAL_STRAIGHT_FLUSH};
  } else if (is_flush && C[4].rank - C[0].rank == 4){
    return {STRAIGHT_FLUSH, C[4].rank};
  } else if (is_flush && C[3].rank == 5 && C[4].rank == 14){
    return {STRAIGHT_FLUSH, 5};
  } else if (C[0].rank == C[3].rank){
    return {FOUR_OF_A_KIND, C[0].rank, C[4].rank};
  } else if (C[1].rank == C[4].rank){
    return {FOUR_OF_A_KIND, C[1].rank, C[0].rank};
  } else if (C[0].rank == C[2].rank && C[3].rank == C[4].rank){
    return {FULL_HOUSE, C[0].rank, C[3].rank};
  } else if (C[2].rank == C[4].rank && C[0].rank == C[1].rank){
    return {FULL_HOUSE, C[2].rank, C[0].rank};
  } else if (is_flush){
    return {FLUSH, C[4].rank, C[3].rank, C[2].rank, C[1].rank, C[0].rank};
  } else if (C[1].rank - C[0].rank == 1 && C[2].rank - C[1].rank == 1 && C[3].rank - C[2].rank == 1 && C[4].rank - C[3].rank == 1){
    return {STRAIGHT, C[4].rank};
  } else if (C[0].rank == 2 && C[1].rank == 3 && C[2].rank == 4 && C[3].rank == 5 && C[4].rank == 14){
    return {STRAIGHT, 5};
  } else if (C[0].rank == C[2].rank){
    return {THREE_OF_A_KIND, C[0].rank, C[4].rank, C[3].rank};
  } else if (C[1].rank == C[3].rank){
    return {THREE_OF_A_KIND, C[1].rank, C[4].rank, C[0].rank};
  } else if (C[2].rank == C[4].rank){
    return {THREE_OF_A_KIND, C[2].rank, C[1].rank, C[0].rank};
  } else if (C[0].rank == C[1].rank && C[2].rank == C[3].rank){
    return {TWO_PAIR, C[2].rank, C[0].rank, C[4].rank};
  } else if (C[0].rank == C[1].rank && C[3].rank == C[4].rank){
    return {TWO_PAIR, C[3].rank, C[0].rank, C[2].rank};
  } else if (C[1].rank == C[2].rank && C[3].rank == C[4].rank){
    return {TWO_PAIR, C[3].rank, C[1].rank, C[0].rank};
  } else if (C[0].rank == C[1].rank){
    return {ONE_PAIR, C[0].rank, C[4].rank, C[3].rank, C[2].rank};
  } else if (C[1].rank == C[2].rank){
    return {ONE_PAIR, C[1].rank, C[4].rank, C[3].rank, C[0].rank};
  } else if (C[2].rank == C[3].rank){
    return {ONE_PAIR, C[2].rank, C[4].rank, C[1].rank, C[0].rank};
  } else if (C[3].rank == C[4].rank){
    return {ONE_PAIR, C[3].rank, C[2].rank, C[1].rank, C[0].rank};
  } else {
    return {HIGH_CARD, C[4].rank, C[3].rank, C[2].rank, C[1].rank, C[0].rank};
  }
}
#line 6 "test/aoj/other/2535.test.cpp"
vector<int> hand2(vector<card> C){
  vector<int> ans;
  vector<int> p = {0, 0, 1, 1, 1, 1, 1};
  while (true){
    array<card, 5> C2;
    int cnt = 0;
    for (int i = 0; i < 7; i++){
      if (p[i] == 1){
        C2[cnt] = C[i];
        cnt++;
      }
    }
    ans = max(ans, hand(C2));
    if (!next_permutation(p.begin(), p.end())){
      break;
    }
  }
  return ans;
}
int main(){
  cout << fixed << setprecision(20);
  while (true){
    vector<card> C(9);
    for (int i = 0; i < 7; i++){
      cin >> C[i];
    }
    if (!cin){
      break;
    }
    string suits = "SHDC";
    int cnt1 = 0, cnt2 = 0;
    for (int s1 = 0; s1 < 4; s1++){
      for (int r1 = 2; r1 <= 14; r1++){
        for (int s2 = 0; s2 < 4; s2++){
          for (int r2 = 2; r2 <= 14; r2++){
            C[7].suit = suits[s1];
            C[7].rank = r1;
            C[8].suit = suits[s2];
            C[8].rank = r2;
            bool ok = true;
            for (int i = 0; i < 9; i++){
              for (int j = i + 1; j < 9; j++){
                if (C[i].suit == C[j].suit && C[i].rank == C[j].rank){
                  ok = false;
                }
              }
            }
            if (ok){
              vector<card> A = {C[0], C[1], C[4], C[5], C[6], C[7], C[8]};
              vector<card> B = {C[2], C[3], C[4], C[5], C[6], C[7], C[8]};
              if (hand2(A) > hand2(B)){
                cnt1++;
              }
              cnt2++;
            }
          }
        }
      }
    }
    cout << (double) cnt1 / cnt2 << endl;
  }
}
Back to top page