题解
计算对手和自身已有牌的和并对M取模 计算过程中统计剩余牌的数量
尝试所有剩余的牌 如果可以赢则赢 不能赢能平就平
AC代码
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int toVal(char *c) //将牌的字符串转为数值
{
if (strlen(c) == 2)
return 10;
if (c[0] == 'A')
return 1;
if (c[0] == 'J')
return 11;
if (c[0] == 'Q')
return 12;
if (c[0] == 'K')
return 13;
return c[0] - '0';
}
int main()
{
#ifdef LOCAL
freopen("C:/input.txt", "r", stdin);
#endif
int T;
cin >> T;
while (T--)
{
int a[14] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; //剩余牌数量
char s[10];
scanf("%s", s);
int M = toVal(s);
a[M]--; //抽出的牌数量需要减少
int x = 0, y = 0, z = 0, v;
for (int i = 0; i < 3; i++) //俩对手求和并取模
scanf("%s", s), v = toVal(s), a[v]--, x = (x + v) % M;
for (int i = 0; i < 3; i++)
scanf("%s", s), v = toVal(s), a[v]--, y = (y + v) % M;
for (int i = 0; i < 2; i++)
scanf("%s", s), v = toVal(s), a[v]--, z = (z + v) % M;
scanf("%s", s);
int flag = -1; //-1输 0不会输 1赢
for (int i = 1; i <= 13; i++)
if (a[i]) //还有牌
{
if ((z + i) % M > max(x, y))
flag = max(flag, 1); //尽量取最优
if ((z + i) % M == max(x, y))
flag = max(flag, 0);
}
if (flag == -1)
cout << "I'm a loser" << endl;
else if (flag == 0)
cout << "I may not lose" << endl;
else
cout << "I can win" << endl;
}
return 0;
}