rt
调了好久,样例都过不去。 样例三个点对两个。
题目链接:Texas hold 'em
代码如下:
#include <bits/stdc++.h>
using namespace std;
int id(string s)
{
if (s == "#") return -1;
int v = 0;
if (s[0] == 'H') v += 13;
if (s[0] == 'D') v += 26;
if (s[0] == 'C') v += 39;
if (s[1] == 'A') v += 12;
else if (s[1] == 'T') v += 8;
else if (s[1] == 'J') v += 9;
else if (s[1] == 'Q') v += 10;
else if (s[1] == 'K') v += 11;
else v += s[1] - '2';
return v;
}
int card[15];
int get()
{
string s;
cin >> s;
return id(s);
}
int po[10];
int calc(int a[])
{
int v[5];
for (int i = 0;i < 5;i++)
v[i] = a[i];
sort(v,v + 5);
if (v[0] / 13 == v[4] / 13)
{
for (int i = 0;i < 5;i++)
v[i] %= 13;
sort(v,v + 5);
if (v[0] == 8 && v[4] == 12) return 90000000;
if (v[0] + 4 == v[4]) return 80000000 + v[4];
if (v[0] + 3 == v[3] && v[0] == 0 && v[4] == 12) return 80000005;
return 50000000 + v[4] * po[4] + v[3] * po[3] + v[2] * po[2] + v[1] * po[1] + v[0];
}
for (int i = 0;i < 5;i++)
v[i] %= 13;
sort(v,v + 5);
if (v[1] == v[2] && v[2] == v[3] && v[3] == v[4]) return 70000000 + v[1] * po[1] + v[0];
if (v[1] == v[2] && v[2] == v[3] && v[3] == v[0]) return 70000000 + v[0] * po[1] + v[4];
if (v[0] == v[1] && v[1] == v[2])
{
if (v[3] == v[4]) return 60000000 + v[0] * po[1] + v[3];
return 30000000 + v[0] * po[2] + v[4] * po[1] + v[3];
}
if (v[2] == v[1] && v[3] == v[2]) return 30000000 + v[1] * po[2] + v[4] * po[1] + v[0];
if (v[2] == v[3] && v[4] == v[2])
{
if (v[0] == v[1]) return 60000000 + v[2] * po[1] + v[0];
return 30000000 + v[2] * po[2] + v[1] * po[1] + v[0];
}
if (v[0] == v[1] && v[2] == v[3]) return 20000000 + v[2] * po[2] + v[0] * po[1] + v[4];
if (v[0] == v[1] && v[4] == v[3]) return 20000000 + v[3] * po[2] + v[0] * po[1] + v[2];
if (v[2] == v[1] && v[4] == v[3]) return 20000000 + v[4] * po[2] + v[1] * po[1] + v[0];
if (v[0] == v[1]) return 10000000 + v[0] * po[3] + v[4] * po[2] + v[3] * po[1] + v[2];
if (v[1] == v[2]) return 10000000 + v[1] * po[3] + v[4] * po[2] + v[3] * po[1] + v[0];
if (v[2] == v[3]) return 10000000 + v[2] * po[3] + v[4] * po[2] + v[1] * po[1] + v[0];
if (v[3] == v[4]) return 10000000 + v[3] * po[3] + v[2] * po[2] + v[1] * po[1] + v[0];
if (v[0] + 3 == v[3] && v[0] == 0 && v[4] == 12) return 40000005;
if (v[0] + 4 == v[4]) return 40000000 + v[4];
return v[4] * po[4] + v[3] * po[3] + v[2] * po[2] + v[1] * po[1] + v[0];
}
bool work()
{
int me[5],opp[5];
int ta = 0,tb = 0;
for (int i = 5;i <= 9;i++)
for (int j = i + 1;j <= 9;j++)
for (int k = j + 1;k <= 9;k++)
{
me[0] = card[1],me[1] = card[2],me[2] = card[i],me[3] = card[j],me[4] = card[k];
ta = max(ta,calc(me));
}
for (int i = 5;i <= 9;i++)
for (int j = i + 1;j <= 9;j++)
for (int k = j + 1;k <= 9;k++)
{
opp[0] = card[3],opp[1] = card[4],opp[2] = card[i],opp[3] = card[j],opp[4] = card[k];
tb = max(tb,calc(opp));
}
return (ta > tb);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
po[1] = 13;
for (int i = 2;i <= 4;i++)
po[i] = po[i - 1] * 13;
while (1)
{
memset(card,0,sizeof(card));
for (int i = 1;i <= 7;i++)
{
card[i] = get();
if (card[i] == -1) return 0;
}
int sum = 0,all = 45 * 44,cnt = 0;
for (int i = 0;i < 52;i++)
{
bool b = 1;
for (int j = 1;j <= 7;j++)
if (i == card[j]) b = 0;
if (!b) continue;
for (int j = 0;j < 52;j++)
{
bool b2 = 1;
for (int k = 1;k <= 7;k++)
if (j == card[k] || j == i) b2 = 0;
if (!b2) continue;
card[8] = i,card[9] = j;
if (work()) sum++;
}
}
cout << fixed << setprecision(20) << 1.0 * sum / all << endl;
}
return 0;
}