标签:des style http color os java io strong for
对应HDU题目:点击打开链接
Fighting the Landlords
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 986 Accepted Submission(s): 360
Problem Description
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, theKicker’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 youin 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.
Input
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, andeach single card will occur at most 4 times totally on two players’ hands
except that the two Jokers each occurs only once.
Output
For each test case, output Yes if you can reach your goal, otherwise output No.
Sample Input
4
33A
2
33A
22
33
22
5559T
9993
Sample Output
题意:就是一人一手牌;问A能否一次出完或者A出牌后B接不了,苦逼刚开始以为A要把整手牌出完(⊙_⊙)。。。
组牌:单张,对子,三条,3夹1, 3夹2(要夹一个对子。。。), 4条(即炸弹), 4夹2(夹的可以是不同的牌),XY(王炸)
思路:先判断A有没有王炸,如有,直接Yes,如果A没有一次出完而B有王炸,直接No,接着判断炸弹如果A有炸弹且比B大,Yes,否则如果B有炸弹,No;之后判断其他(顺序随便)。。。
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
const int MAXN=1000+10;
using namespace std;
struct Card//保存两人手里各种组牌(如3夹2,4夹2等等)的最大值
{
Card(){one=0;two=0;three=0;three_1=0;three_2=0;four=0;four_2=0;xy=0;len=0;}
int one,two,three,three_1,three_2,four,four_2,xy,len;
};
void cal(char *s, int *num)//计算各种牌有多少个,如num[14]表示A有num[14]张
{
for(int i=0; i<strlen(s); i++){
if(s[i]=='T') num[10]++;
if(s[i]=='J') num[11]++;
if(s[i]=='Q') num[12]++;
if(s[i]=='K') num[13]++;
if(s[i]=='A') num[14]++;
if(s[i]=='2') num[15]++;//注意这里。。。不要放到num[2]那里了
if(s[i]=='X') num[16]++;
if(s[i]=='Y') num[17]++;
if('3'<=s[i] && s[i]<='9') num[s[i]-'0']++;
}
}
void attack(Card &c, int *num)//计算c的各组牌的最大值
{
if(num[16] && num[17]) c.xy=1;
for(int i=3; i<=17; i++){
if(num[i]) c.one=i;
if(num[i]>=2) c.two=i;
if(num[i]>=3) c.three=i;
if(num[i]>=4) c.four=i;
if(num[i]>=4 && c.len>=6) c.four_2=i;
if(num[i]>=3 && c.len>=5){
for(int j=1; j<=15; j++)
if(i!=j && num[j]>=2) {c.three_2=i;break;}
}
if(num[i]>=3 && c.len>=4) c.three_1=i;
}
}
bool first(char *s, Card c)//判断能否一次出完
{
int len=strlen(s);
if(c.xy && 2==len) return 1;
if(c.four && 4==len) return 1;
if(c.four_2 && 6==len) return 1;
if(c.three_2 && 5==len) return 1;
if(c.three_1 && 4==len) return 1;
if(c.three && 3==len) return 1;
if(c.two && 2==len) return 1;
if(c.one && 1==len) return 1;
return 0;
}
int main()
{
//freopen("in.txt","r",stdin);
char s1[20],s2[20];
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s%s", s1,s2);
Card c1,c2;
c1.len=strlen(s1);
c2.len=strlen(s2);
int num1[20]={0},num2[20]={0};
cal(s1,num1);
cal(s2,num2);
attack(c1,num1);
attack(c2,num2);
if(first(s1,c1)) {printf("Yes\n");continue;}//一次出完
if(c1.xy) {printf("Yes\n");continue;}//有王炸
if(c2.xy) {printf("No\n");continue;}//对方有王炸
if(c1.four && c1.four >= c2.four) {printf("Yes\n");continue;}//有炸弹且比对方大
else {if(c2.four) {printf("No\n");continue;}}//这里也错了不少次。。。
if(c1.three_2 && c1.three_2 >= c2.three_2) {printf("Yes\n");continue;}//有3夹2且比对方大
if(c1.one >= c2.one) {printf("Yes\n");continue;}//单张比对方大
if(c1.two && c1.two >= c2.two) {printf("Yes\n");continue;}//有对子且比对方大
if(c1.three && c1.three >= c2.three) {printf("Yes\n");continue;}//有3条且比对方大
if(c1.three_1 && c1.three_1 >= c2.three_1) {printf("Yes\n");continue;}//有3夹1且比对方大
printf("No\n");
}
return 0;
}
模拟斗地主——HDU 4930
标签:des style http color os java io strong for
原文地址:http://blog.csdn.net/u013351484/article/details/38850427