您的位置:首页 > 其它

hdu 4930 Fighting the Landlords(模拟)

2017-01-19 17:31 477 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4930

Fighting the Landlords

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

Total Submission(s): 1337 Accepted Submission(s): 492

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, 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.

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, and each 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

Yes

No

Yes

Yes

分析

这是一道模拟好题呀,(相当考验的我的耐心)。

样例数据有些弱,要自己出数据才能测出一些bug

判断的顺序

1.能不能一次出完?

2.有没有王炸

3.比较炸弹

4.比较个子,对子,三带,四带

#include<iostream>
#include<map>
#include<set>
using namespace std;
map<char,int> func;
int main(){
//freopen("in.txt","r",stdin);
int n;
cin>>n;
for(int i=3;i<=9;i++)
func[i+'0']=i;
func['T']=10;
func['J']=11;
func['Q']=12;
func['K']=13;
func['A']=14;
func['2']=15;
func['X']=16;
func['Y']=17;
while(n--){
string a,b;
map<char,int> ma,mb;
cin>>a>>b;
for(int i=0;i<a.size();i++){
ma[a[i]]++;
}

int wa1=0,wa2=0,wb1=0,wb2=0;

map<char,int>::iterator it=ma.begin();
set<char> na1,na2,na3,na4;
for(;it!=ma.end();it++){
if(ma['Y']==1)
wa1=1;
if(ma['X']==1)
wa2=1;

if(it->second==4)
na4.insert(it->first);
if(it->second==3)
na3.insert(it->first);
if(it->second==2)
na2.insert(it->first);
if(it->second==1)
na1.insert(it->first);
}

for(int i=0;i<b.size();i++){
mb[b[i]]++;
}
set<char> nb1,nb2,nb3,nb4;
it=mb.begin();
for(;it!=mb.end();it++){
if(mb['Y']==1)
wb1=1;
if(mb['X']==1)
wb2=1;

if(it->second==4)
nb4.insert(it->first);
if(it->second==3)
nb3.insert(it->first);
if(it->second==2)
nb2.insert(it->first);
if(it->second==1)
nb1.insert(it->first);
}
set<char>::iterator is;

//if 1 time go ,must win
int now=0;
if(a.size()<=6){
if(a.size()==6){
if(na4.size()==1){
cout<<"Yes"<<endl;
now=1;
}
}
if(a.size()==5){
if(na3.size()==1&&na2.size()==1){
cout<<"Yes"<<endl;
now=1;
}
}
if(a.size()==4 ){
if(na4.size()==1 || (na3.size()==1&&na1.size()==1) ){
cout<<"Yes"<<endl;
now=1;
}
}
if(a.size()==3){
if(na3.size()==1){
cout<<"Yes"<<endl;
now=1;
}
}
if(a.size()==2){
if(na2.size()==1){
cout<<"Yes"<<endl;
now=1;
}
}
if(a.size()==1){
cout<<"Yes"<<endl;
now=1;
}
}
if(now)
continue;

//if double joker ,must win
if(wa1&&wa2){
//cout<<"double Joker"<<endl;
cout<<"Yes"<<endl;
now=1;
}
else if(wb1&&wb2){
cout<<"No"<<endl;
now=1;
}
if(now)
continue;

// 4-num boom
int numa=0,numb=0;
for(is=na4.begin();is!=na4.end();is++){
if(is!=na4.end()&&func[*is]>numa){
numa=func[*is];
}
}
for(is=nb4.begin();is!=nb4.end();is++){
if(is!=nb4.end()&&func[*is]>numb){
numb=func[*is];
}
}
if(numa>numb&&numa){
//cout<<"boom"<<endl;
cout<<"Yes"<<endl;
now=1;
}
else if(numa<numb){
cout<<"No"<<endl;
now=1;
}
if(now)
continue;

// No boom, compare Solo
numa=0,numb=0;
for(int i=0;i<a.size();i++){
if(func[a[i]]>numa)
numa=func[a[i]];
}
for(int i=0;i<b.size();i++){
if(func[b[i]]>numb)
numb=func[b[i]];
}

if(numa>=numb&&numa){
//cout<<"Solo"<<endl;
cout<<"Yes"<<endl;
now=1;
}
if(now)
continue;

// compare Pair
numa=0,numb=0;
for(is=na2.begin();is!=na2.end();is++){
if(is!=na2.end()&&func[*is]>numa){
numa=func[*is];
}
}
for(is=nb2.begin();is!=nb2.end();is++){
if(is!=nb2.end()&&func[*is]>numb){
numb=func[*is];
}
}
if(numa>=numb&&numa){
//cout<<"Pair"<<endl;
cout<<"Yes"<<endl;
now=1;
}
if(now)
continue;
// Compare Trio
//case 1 777+x>444+y
numa=0,numb=0;
for(is=na3.begin();is!=na3.end();is++){
if(is!=na3.end()&&func[*is]>numa){
numa=func[*is];
}
}
for(is=nb3.begin();is!=nb3.end();is++){
if(is!=nb3.end()&&func[*is]>numb){
numb=func[*is];
}
}
if(numa>=numb&&numa){
//cout<<"Trio"<<endl;
//cout<<"numa="<<numa<<endl;
//cout<<"numb="<<numb<<endl;
cout<<"Yes"<<endl;
now=1;
}
else if(numa < numb &&numa ){
if(na2.size()&& na2.size()==0){
cout<<"Yes"<<endl;
now=1;
}
if(a.size()>3 &&b.size()==3){
cout<<"Yes"<<endl;
now=1;
}
}
if(now)
continue;
cout<<"No"<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: