标签:des style http color os java io strong for
对应HDU题目:点击打开链接
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 986 Accepted Submission(s): 360
4 33A 2 33A 22 33 22 5559T 9993
Yes No Yes Yes
题意:就是一人一手牌;问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;
}
标签:des style http color os java io strong for
原文地址:http://blog.csdn.net/u013351484/article/details/38850427