您的位置:首页 > 其它

HDU 4930 Fighting the Landlords 模拟

2014-12-29 16:20 411 查看
传送门:点击打开链接

Fighting the Landlords

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 1105 Accepted Submission(s): 401

[align=left]Problem Description[/align]
Fighting the Landlords is a card game which has been a heat for years in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 17. The Landlord wins if
he/she has no cards left, and the farmer team wins if either of the Farmer have no cards left. The game uses the concept of hands, and some fundamental rules are used to compare the cards. For convenience, here we only consider the following categories of
cards:

1.Solo: a single card. The priority is: Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. It’s the basic rank of cards.

2.Pair : two matching cards of equal rank (e.g. 3-3, 4-4, 2-2 etc.). Note that the two Jokers cannot form a Pair (it’s another category of cards). The comparison is based on the rank of Solo, where 2-2 is the highest, A-A comes second, and 3-3 is the lowest.

3.Trio: three cards of the same rank (e.g. 3-3-3, J-J-J etc.). The priority is similar to the two categories above: 2-2-2 > A-A-A > K-K-K > . . . > 3-3-3.

4.Trio-Solo: three cards of the same rank with a Solo as the kicker. Note that the Solo and the Trio should be different rank of cards (e.g. 3-3-3-A, 4-4-4-X etc.). Here, the
Kicker’s rank is irrelevant to the comparison, and the Trio’s rank determines the priority. For example, 4-4-4-3 > 3-3-3-2.

5.Trio-Pair : three cards of the same rank with a Pair as the kicker (e.g. 3-3- 3-2-2, J-J-J-Q-Q etc.). The comparison is as the same as Trio-Solo, where the Trio is the only factor to be considered. For example,4-4-4-5-5 > 3-3-3-2-2. Note again, that two jokers
cannot form a Pair.

6.Four-Dual: four cards of the same rank with two cards as the kicker. Here,
it’s allowed for the two kickers to share the same rank.
The four same cards dominates the comparison: 5-5-5-5-3-4 > 4-4-4-4-2-2.

In the categories above, a player can only beat the prior hand using of the same category but not the others. For example, only a prior Solo can beat a Solo while a Pair cannot. But there’re exceptions:

7.Nuke: X-Y (JOKER-joker). It can beat everything in the game.

8.Bomb: 4 cards of the same rank. It can beat any other category except Nuke or another Bomb with a higher rank. The rank of Bombs follows the rank of individual cards: 2-2-2-2 is the highest and 3-3-3-3 is the lowest.

Given the cards of both yours and the next player’s, please judge whether you have a way to play a hand of cards that the next player cannot beat you
in this round. If you no longer have cards after playing, we consider that he cannot beat you either. You may see the sample for more details.

[align=left]Input[/align]
The input contains several test cases. The number of test cases T (T<=20) occurs in the first line of input.

Each test case consists of two lines. Both of them contain a string indicating your cards and the next player’s, respectively. The length of each string doesn’t exceed 17, and
each single card will occur at most 4 times totally on two players’ hands except that the two Jokers each occurs only once.

[align=left]Output[/align]
For each test case, output Yes if you can reach your goal, otherwise output No.

[align=left]Sample Input[/align]

4
33A
2
33A
22
33
22
5559T
9993


[align=left]Sample Output[/align]

Yes
No
Yes
Yes


[align=left]Author[/align]
BUPT

[align=left]Source[/align]
2014 Multi-University Training Contest 6

题意:斗地主,问这轮是否存在一种出牌的方式,使对方无法跟牌。若本轮能把牌出完,也算达到目的。

大小关系不再赘述。可以出单,对,三,三带一,三带对,四带二,对鬼,炸弹。

思路:先检查有没有方法让所有牌全部出掉,如果没有的话再每一种出牌方式进行比较。出牌方式应该要有优先级的考虑,如对鬼的优先级最高,它可以秒杀一切。出了之后保证对方要不起。

详细参见代码。

#include<cstdio>
#include<cstring>
#include<cctype>
#include<iostream>
using namespace std;
int Solo(int a[])
{
for (int i = 17; i >= 3; i--)
if (a[i]) return i;
return 0;
}
int Pair(int a[])
{
for (int i = 17; i >= 3; i--)
if (a[i] >= 2) return i;
return 0;
}
int Trio(int a[])
{
for (int i = 17; i >= 3; i--)
if (a[i] >= 3) return i;
return 0;
}
int Trio_Solo(int a[])
{
int k = Trio(a);
if (k == 0) return 0;
else
{
a[k] -= 3;
for (int j = 17; j >= 3; j--)
if (a[j])
{
a[k] += 3;
return k;
}
a[k] += 3;
return 0;
}
}
int Trio_Pair(int a[])
{
int k = Trio(a);
if (k == 0) return 0;
else
{
a[k] -= 3;
for (int j = 17; j >= 3; j--)
if (a[j] >= 2)
{
a[k] += 3;
return k;
}
a[k] += 3;
return 0;
}
}
int Bomb(int a[])
{
for (int i = 17; i >= 3; i--)
if (a[i] == 4) return i;
return 0;
}
int Four_Dual(int a[])
{
int k = Bomb(a);
if (k == 0) return 0;
a[k] -= 4;
for (int i = 17; i >= 3; i--)
if (a[i])
{
a[i]--;
for (int j = 17; j >= 3; j--)
if (a[j])
{
a[i]++;
a[k] += 4;
return k;
}
a[i]++;
}
a[k]++;
return 0;
}
int Nuke(int a[])
{
if (a[17] && a[16]) return 1;
return 0;
}
int a[20], b[20];
char sa[50], sb[50];
void init()
{
scanf("%s %s", sa, sb);
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int len, i;
len = strlen(sa);
for (i = 0; i<len; i++)
if (isdigit(sa[i]) && sa[i] != '2') a[sa[i] - 48]++;
else if (sa[i] == 'Y') a[17]++;
else if (sa[i] == 'X') a[16]++;
else if (sa[i] == '2') a[15]++;
else if (sa[i] == 'A') a[14]++;
else if (sa[i] == 'K') a[13]++;
else if (sa[i] == 'Q') a[12]++;
else if (sa[i] == 'J') a[11]++;
else if (sa[i] == 'T') a[10]++;
len = strlen(sb);
for (i = 0; i<len; i++)
if (isdigit(sb[i]) && sb[i] != '2') b[sb[i] - 48]++;
else if (sb[i] == 'Y') b[17]++;
else if (sb[i] == 'X') b[16]++;
else if (sb[i] == '2') b[15]++;
else if (sb[i] == 'A') b[14]++;
else if (sb[i] == 'K') b[13]++;
else if (sb[i] == 'Q') b[12]++;
else if (sb[i] == 'J') b[11]++;
else if (sb[i] == 'T') b[10]++;
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
init();
int sum = 0;
int i;
for (i = 3; i <= 17; i++) sum += a[i];
bool ok = 0;
if (Nuke(a)) ok = 1;
else if (sum == 6 && Four_Dual(a)) ok = 1;
else if (sum == 5 && Trio_Pair(a)) ok = 1;
else if (sum == 4 && Bomb(a)) ok = 1;
else if (sum == 4 && Trio_Solo(a)) ok = 1;
else if (sum == 3 && Trio(a)) ok = 1;
else if (sum == 2 && Pair(a)) ok = 1;
else if (sum == 1 && Solo(a)) ok = 1;
else if (Nuke(b)) ok = 0;
else if (Bomb(a) && Bomb(a) >= Bomb(b)) ok = 1;
else if (Bomb(b)) ok = 0;
else if (Solo(a) && Solo(a) >= Solo(b)) ok = 1;
else if (Pair(a) && Pair(a) >= Pair(b)) ok = 1;
else if (Trio(a) && Trio(a) >= Trio(b)) ok = 1;
else ok = 0;
if (ok) printf("Yes\n");
else printf("No\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: