NC25451. HRY and fight the landlord
描述
输入描述
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; }