列表

详情


NC25451. HRY and fight the landlord

描述

In a parallel universe, HRY is a gambling expert. This time, he is playing Fight the Landlord with the pumpkin, 10256 at the table!
As everyone knows, when playing Fight the Landlord, HRY is sure to try to be the landlord. This time he also got the wish to be the landlord!
Whoa! He's got good luck!
After a few rounds, HRY has already played some cards (or maybe zero cards). Now it's HRY's turn again. He wants to know if he can play all the remaining cards he has in this round.

Rules of Fight the Landlord:
The deck consists of 54 cards. From small to large, the points are 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < J < Q < K < A < 2 < W1 < W2. For W1 and W2 there is only 1 card for each and for other points they have 4 cards for each. At the beginning, the landlord has 20 cards, and the two civilians have 17 cards. The landlord plays first.

The types of card that can be played in a round:
Single: Any single card can be used as a Single, such as J or W2. 
Pair: Any two cards with the same point, such as 3 3 or Q Q. But W1 W2 is not a Pair.
Triple: Any three cards with the same point, such as 9 9 9.
Triple plus a Single: A "Triple" and a "Single". The points of the "Triple" and the "Single" must be different, such as 10 10 10 9.
Triple plus a Pair: A "Triple" and a "Pair", such as 7 7 7 K K.
Single Straight: Five or more consecutive "Singles", excluding 2, W1, W2. Such as 3 4 5 6 7 8 or 6 7 8 9 10 J Q K A. 
Pair Straight: Three or more consecutive "Pairs", excluding 2, W1, W2. Such as 3 3 4 4 5 5 or 5 5 6 6 7 7 8 8. 
Triple Straight: Two or more consecutive "Triples", excluding 2, W1, W2. Such as 4 4 4 5 5 5 or J J J Q Q Q K K K.
Airplane No. 1: Two or more consecutive "Triple plus a Single", excluding "Triple" 2 2 2. For example, 3 3 3 9 4 4 4 2 or K K K 10 A A A 10 are valid, but A A A 3 2 2 2 4 is not valid. "Consecutive" here means that the point of the "Triple" in each "Triple plus a Single" is consecutive. 
Airplane No. 2: Two or more consecutive "Triple plus a Pair", excluding "Triple" 2 2 2. For example, J J J 2 2 Q Q Q 8 8 or 7 7 7 3 3 8 8 8 3 3 are valid, but A A A 3 3 2 2 2 K K is not vaild. "Consecutive" here means that the point of the "Triple" in each "Triple plus a Pair" is consecutive. 
Bomb: Any four cards with the same point, such as 3 3 3 3 or K K K K. 
Rocket: The combination of W1 and W2. 
Quartet plus two Singles: One
Bomb" and two "Singles" (two Singles can be the same), such as 4 4 4 4 5 A or 4 4 4 4 K K.

Note: For "Triple plus a Single" and "Quartet plus two Singles", the Single can be W1 or W2.

If the above rules are different from the rules you have seen, please follow the above rules.

输入描述

The first line of input contains an integer T, indicating the number of test case.
For each test case :
The first line contains a positive integer n, indicating the number of cards HRY still has in his hand.
The second line contains n strings separated by spaces, indicating the cards HRY still has.

It is guaranteed that the input is valid.

输出描述

For each test case output a line. If he can play all of his cards in this round, output "Ye5", else output "N0"(without quotes).

示例1

输入:

11
12
3 4 5 6 7 8 9 10 J Q K A
13
3 4 5 6 7 8 9 10 J Q K A 2
7
6 6 7 7 8 8 8
10
3 3 3 4 4 4 5 5 5 5
8
9 9 9 10 10 10 W1 W2
12
6 6 6 7 7 7 8 8 8 7 8 9
5
4 4 4 4 5
6
2 2 2 2 3 A
7
4 4 4 5 5 5 W2
6
K K A A 2 2
5
3 3 3 W1 W2

输出:

Ye5
N0
N0
Ye5
Ye5
Ye5
N0
Ye5
N0
N0
N0

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 98ms, 内存消耗: 612K, 提交时间: 2019-04-27 17:23:00

/**
**      author:XiaKIsGod
**      time:2019.4
**/
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define endl "\n"
#define FIN freopen("1.in","r",stdin)
#define mem(x,v) memset(x,v,sizeof(x))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
using namespace std;
const int N = 1000000;
int T;
string card="34567890JQKA2wW";
string SS="34567890JQKA";
string PS="3344556677889900JJQQKKAA";
string TS="333444555666777888999000JJJQQQKKKAAA";
int cnt[20],cnt2[10];
void read(int n){
    for(int i=0;i<n;i++){
        string tmp;
        cin>>tmp;
        if(tmp=="10")
            tmp="0";
        else if(tmp=="W1")
            tmp="w";
        else if(tmp=="W2")
            tmp="W";
        for(int i=0;i<15;i++){
            if(card[i]==tmp[0]){
                cnt[i]++;
                break;
            }
        }
    }
}
string cal(){
    string str;
    for(int i=0;i<15;i++){
        for(int j=0;j<cnt[i];j++){
            str+=card[i];
        }
        if(i<13){
            cnt2[cnt[i]]++;
        }
    }
    return str;
}
bool judge1(string str){//顺子
    //cout<<1;
    return SS.find(str)!=SS.npos&&str.size()>=5&&cnt2[1]*1==str.size();
}
bool judge2(string str){//连对
    //cout<<2;
    return PS.find(str)!=PS.npos&&str.size()>=6&&cnt2[2]*2==str.size();
}
bool judge3(string str){//对子
   // cout<<3;
    return str[0]==str[1]&&str.size()==2;
}
bool judge4(string str){//单
    //cout<<4;
    return str.size()==1;
}
bool judge5(string str){//3张
    //cout<<5;
    return cnt2[3]*3==str.size()&&cnt2[3]==1;
}
bool judge6(string str){//3张连
    //cout<<6;
    return cnt2[3]*3==str.size()&&TS.find(str)!=TS.npos&&cnt2[3]>=2;
}
bool judge7(string str){//plane or 3 by 1 or 3 by 2
    //cout<<7;
    for(int i=0;i<13;i++){
        if(cnt[i]>=3){
            int len=1,pos=i+1;
            if(len*3+len==str.size()){
                return true;
            }
            while(cnt[pos]>=3&&pos<12){
                len++;
                pos++;
                if(len*3+len==str.size()){
                    return true;
                }
        	}
        }
        if(cnt[i]==3){
        	int len=1,pos=i+1;
        	if(len*5==str.size()&&cnt2[2]+cnt2[4]*2==len){
        		return true;
			}
			while(cnt[pos]==3&&pos<12){
				len++;
				pos++;
				if(len*5==str.size()&&cnt2[2]+cnt2[4]*2==len)
        			return true;
			}
		}
    }
    return false;
}
bool judge8(string str){//bomb
   // cout<<8;
    return str.size()==4&&cnt2[4]==1;
}
bool judge9(string str){//Rocket
    //cout<<9;
    return str=="wW";
}
bool judge10(string str){//4 by 2
    //cout<<10;
    return cnt2[4]==1&&str.size()==6;
}
void solve (){
    memset(cnt,0,sizeof cnt);
    memset(cnt2,0,sizeof cnt2);
    int n;
    string have="";
    cin>>n;
    read(n);
    have=cal();
    bool tag=false;
    //cout <<have<<endl;
    if(judge1(have)||judge2(have)||judge3(have)||judge4(have)||judge5(have)||judge6(have)||judge7(have)||judge8(have)||judge9(have)||judge10(have))
        tag=true;
    if(tag)
        cout<<"Ye5"<<endl;
    else cout<<"N0"<<endl;
}

int main(){
    //freopen("input.txt","r",stdin);
    cin>>T;
	while(T--){
        solve();
	}
	return 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 129ms, 内存消耗: 504K, 提交时间: 2019-09-14 23:06:21

#include <bits/stdc++.h>
using namespace std;
string scard[8]={"10","J","Q","K","A","2","W1","W2"};
#define cls(x) memset(x,0,sizeof(x))
map<string,int> c2i;
int id(string s){
    if(c2i[s])return c2i[s];
    else return s[0]-'0';
}
int T,n,c[20],cc[5],d[5],dd[5];
int main(){
    for(int i=0;i<8;i++)c2i[scard[i]]=i+10;
    scanf("%d",&T);
    while(T--){
        cls(c),cls(cc),cls(d),cls(dd);
        char s[5];
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf(" %s",s);
            c[id(s)]++;
        }
        for(int i=0;i<20;i++)cc[c[i]]++;
        for(int i=1;i<5;i++){
            int t=0,tt=0;
            for(int j=0;j<15;j++){
                if(c[j]==i){
                    t++;
                    if(t>d[i])d[i]=t;
                }else t=0;
                if(c[j]>=i){
                    tt++;
                    if(tt>dd[i])dd[i]=tt;
                }else tt=0;
            }
        }
        if( n==1||
            n==2&&cc[2]==1||
            n==3&&cc[3]==1||
            n==4&&cc[3]==1&&cc[1]==1||
            n==5&&cc[3]==1&&cc[2]==1||
            d[1]>=5&&n==d[1]||
            d[2]>=3&&n==d[2]*2||
            d[3]>=2&&n==d[3]*3||
            dd[3]>=2&&n==dd[3]*4||dd[3]>=4&&n-dd[3]*3==dd[3]%4||
            d[3]>=2&&n==d[3]*5&&d[3]==cc[2]+2*cc[4]||
            n==4&&cc[4]==1||
            n==2&&c[16]==1&&c[17]==1||
            n==6&&cc[4]==1)puts("Ye5");
        else puts("N0");
    }
    return 0;
}

上一题