Created
January 20, 2019 17:09
-
-
Save cbdavide/fe1593a649bd2ec6978d63b7123e13bb to your computer and use it in GitHub Desktop.
Uva 462 - Bridge Hand Evaluator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define F first | |
#define S second | |
#define endl '\n' | |
#define PB push_back | |
typedef long long ll; | |
typedef vector<ll> vll; | |
typedef pair<double, double> ii; | |
typedef vector<ii> vii; | |
typedef vector<int> vi; | |
typedef pair<int, char> ic; | |
typedef vector<char> vc; | |
typedef map<char, vc> cvc; | |
const int oo = ~(1<<31); | |
const double EPS = 1e-9; | |
char R[13], S[13]; | |
char suits[4] = {'S', 'H', 'D', 'C'}; | |
cvc group() { | |
cvc T; | |
for(int i=0; i<13; i++) | |
T[S[i]].PB(R[i]); | |
return T; | |
} | |
int substract(cvc &T, char s, int ammount) { | |
int cont = 0; | |
for(auto p : T) { | |
int c=0, h=0; | |
for(char i : p.S) { | |
if(i != s)c++; | |
else h++; | |
} | |
if(c <= ammount) | |
cont += h; | |
} | |
return cont; | |
} | |
int sum(cvc &T) { | |
int sum = 0; | |
for(auto p: T) { | |
for(char c : p.S) { | |
if(c == 'A') sum += 4; | |
else if(c == 'K') sum += 3; | |
else if(c == 'Q') sum += 2; | |
else if(c == 'J') sum += 1; | |
} | |
} | |
return sum; | |
} | |
int add(cvc &T) { | |
int s = 0; | |
for(int i=0; i<4; i++) { | |
vc C = T[suits[i]]; | |
if(!C.size()) s += 2; | |
else if(C.size() == 1) s += 2; | |
else if(C.size() == 2) s += 1; | |
} | |
return s; | |
} | |
bool has_a(vc &C, char l) { | |
for(char c: C) if(c == l) | |
return true; | |
return false; | |
} | |
bool are_stopped(cvc &T) { | |
for(int i=0; i<4; i++) { | |
vc C = T[suits[i]]; | |
if(has_a(C, 'A')) | |
continue; | |
if(C.size() >= 2 && has_a(C, 'K')) | |
continue; | |
if(C.size() >= 3 && has_a(C, 'Q')) | |
continue; | |
return false; | |
} | |
return true; | |
} | |
char get_max(cvc &T) { | |
int mx = -1; | |
for(auto p: T) | |
mx = max(mx, (int)p.S.size()); | |
for(int i=0; i<4; i++) { | |
if(T[suits[i]].size() == mx) | |
return suits[i]; | |
} | |
return 'f'; | |
} | |
int main() { | |
#ifndef CBDAVIDES | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
#endif | |
while(cin >> R[0] >> S[0]) { | |
for(int i=1; i<13; i++) | |
cin >> R[i] >> S[i]; | |
cvc T = group(); | |
int s = sum(T); | |
s -= substract(T, 'K', 0); | |
s -= substract(T, 'Q', 1); | |
s -= substract(T, 'J', 2); | |
if(s >= 16 && are_stopped(T)) { | |
cout << "BID NO-TRUMP" << endl; | |
continue; | |
} | |
s += add(T); | |
if(s < 14) cout << "PASS" << endl; | |
else cout << "BID " << get_max(T) << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment