hdu 4930 Fighting the Landlords (類比)

來源:互聯網
上載者:User

標籤:des   style   color   java   os   io   strong   for   

Fighting the LandlordsTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 160    Accepted Submission(s): 52


Problem DescriptionFighting 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.
 
InputThe 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. 
OutputFor each test case, output Yes if you can reach your goal, otherwise output No. 
Sample Input
433A233A2233225559T9993
 
Sample Output
YesNoYesYes
 

題意:兩個人打撲克,規則參照鬥地主。問先手能否一次出完牌或者出的第一手牌讓對方無牌可出!!

類比就是了:

#include"stdio.h"#include"string.h"#define N 20#define M 100int a[N],b[N],n,m;char s[N];int max(int a,int b){    return a>b?a:b;}void inti(char*s,int f){    int i,t;    for(i=0;s[i]!='\0';i++)    {        if(s[i]>='3'&&s[i]<='9')        {            t=s[i]-'0'-2;        }        else if(s[i]=='T')            t=8;        else if(s[i]=='J')            t=9;        else if(s[i]=='Q')            t=10;        else if(s[i]=='K')            t=11;        else if(s[i]=='A')            t=12;        else if(s[i]=='2')            t=13;        else if(s[i]=='X')            t=14;        else if(s[i]=='Y')            t=15;        if(f==1)            a[t]++;        else            b[t]++;    }}int escape(){    int i;    if(n==1)         //枚舉我方有幾張牌,能否一次出完        return 1;    if(n==2)              {        int n2=0;        for(i=1;i<14;i++)            if(a[i]==2)                n2++;        if(n2==1)            return 1;    }    if(n==3)    {        int n3=0;        for(i=1;i<14;i++)            if(a[i]==3)                n3++;        if(n3==1)            return 1;    }    if(n==4)    {        int n3=0;        for(i=1;i<14;i++)        {            if(a[i]>=3)                n3++;        }        if(n3==1)            return 1;    }    if(n==5)    {        int n2=0,n3=0;        for(i=1;i<14;i++)        {            if(a[i]==3)                n3++;            if(a[i]==2)                n2++;        }        if(n2==1&&n3==1)            return 1;    }    if(n==6)    {        int n4=0;        for(i=1;i<14;i++)        {            if(a[i]==4)                n4++;        }        if(n4==1)            return 1;    }    return 0;}int beat(){    int i,j;    if(a[14]==1&&a[15]==1)        return 1;    if(b[14]==1&&b[15]==1)        return 0;           //對方有王炸    for(i=13;i>0;i--)        if(a[i]==4)            break;    for(j=13;j>0;j--)        if(b[j]==4)            break;    if(j>0)        //對方有炸彈,    {        if(i>=j)            return 1;        else            return 0;    }          if(n>=5)             //下面就是對方沒有炸彈,    {                    //出3帶2,下面3帶1就不用枚舉了        int a3,a2,b3,b2;        a3=a2=b3=b2=0;        for(i=13;i>0;i--)        {            if(a[i]==3)                a3=max(a3,i);            if(a[i]==2)                a2=max(a2,i);        }        for(j=13;j>0;j--)        {            if(b[j]==3)                b3=max(b3,j);            if(b[j]==2)                b2=max(b2,j);        }        if(a3!=0&&a2!=0)        {            if(a3>=b3||b2==0)                return 1;        }    }              //四張牌只能是炸彈或者3帶1,    if(n>=3)    {        for(i=13;i>0;i--)            if(a[i]>=3)                break;        for(j=13;j>0;j--)            if(b[j]>=3)                break;        if(i!=0)        {            if(i>=j)                return 1;        }    }    if(n>=2)    {        for(i=13;i>0;i--)            if(a[i]>=2)                break;        for(j=13;j>0;j--)            if(b[j]>=2)                break;        if(i!=0)        {            if(i>=j)                return 1;        }    }    if(n>=1)            //出一張牌 無炸彈    {        for(i=15;i>0;i--)            if(a[i])                break;        for(j=15;j>0;j--)            if(b[j])                break;        if(i>=j)            return 1;    }    return 0;}int main(){    int T;    scanf("%d",&T);    while(T--)    {        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        scanf("%s",s);        n=strlen(s);                 inti(s,1);        scanf("%s",s);        m=strlen(s);        inti(s,2);        if(escape())        //能否一次把牌出完        {            printf("Yes\n");            continue;        }        if(beat())        //第一手牌無敵            printf("Yes\n");        else            printf("No\n");    }    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.