HDU 4930 fighting the landlords)

Source: Internet
Author: User

Fighting the landlords


Note:

Fighting landlords .... The two cards are valid. The order of the card size 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.

8 combinations: 1. Single Card: One Card

2. Pair: two identical cards

3. trio (translated by Baidu ..) : Three identical cards

4. Three-belt-one: three identical cards with one card (the size is based on the previous card, not on the card)

5. Three-belt two: three identical cards with two cards, the two cards can be the same or different (the size is only the front card, not the belt)

6. Four-band Two: four identical cards with two cards, the two cards can be the same or different (the size is only the front card, not the belt)

7. Bombs: four identical bombs come out together without anything (except nuclear bombs)

8. nuclear bombs: big and small kings (can manage all cards)

Then the rule is actually very simple, that is, if you leave first, if you do not have a hand card, output yes, or after you leave, the other party is not bigger than you, yes is also output, and no is output...


Ideas:

The game has been stuck at 1007, t to death .... I did not come to care about this question either .. In fact, it is not difficult ..

Pay attention to the following points:

1. It cannot be four-to-one.

2. A bomb can take four to two

3. Understand When to output Yes


The purpose of posting this blog is not to stick code, but to write code too frustrating .... Let's take a look at the description of the question .... I just want to record this question -. -I'm bored ~

#include <stdio.h>#include <string.h>int Hash1[20], Hash2[20];int T;char s1[20], s2[20];int main(){    scanf("%d", &T);    while(T--){        memset(Hash1, 0, sizeof(Hash1));        memset(Hash2, 0, sizeof(Hash2));        scanf("%s", s1);        int len1 = strlen(s1);        for(int i = 0; i < len1; ++i){            if(s1[i] >= '3' && s1[i] <= '9'){                Hash1[s1[i]-'0']++;            }            else if(s1[i] == 'T'){                Hash1[10]++;            }            else if(s1[i] == 'J'){                Hash1[11]++;            }            else if(s1[i] == 'Q'){                Hash1[12]++;            }            else if(s1[i] == 'K'){                Hash1[13]++;            }            else if(s1[i] == 'A'){                Hash1[14]++;            }            else if(s1[i] == '2'){                Hash1[15]++;            }            else if(s1[i] == 'X'){                Hash1[16]++;            }            else if(s1[i] == 'Y'){                Hash1[17]++;            }        }//        for(int i = 3; i <= 17; ++i){//            printf("%d ", Hash1[i]);//        }        scanf("%s", s2);        int len2 = strlen(s2);        for(int i = 0; i < len2; ++i){            if(s2[i] >= '3' && s2[i] <= '9'){                Hash2[s2[i]-'0']++;            }            else if(s2[i] == 'T'){                Hash2[10]++;            }            else if(s2[i] == 'J'){                Hash2[11]++;            }            else if(s2[i] == 'Q'){                Hash2[12]++;            }            else if(s2[i] == 'K'){                Hash2[13]++;            }            else if(s2[i] == 'A'){                Hash2[14]++;            }            else if(s2[i] == '2'){                Hash2[15]++;            }            else if(s2[i] == 'X'){                Hash2[16]++;            }            else if(s2[i] == 'Y'){                Hash2[17]++;            }        }//        for(int i = 3; i <= 17; ++i){//            printf("%d ", Hash2[i]);//        }        if(Hash1[16] == 1 && Hash1[17] == 1){            printf("Yes\n");            continue;        }        ///clear        int cnt = 0;        for(int i = 3; i <= 17; ++i){            if(Hash1[i] > 0){                cnt++;            }        }        if(cnt == 1){            printf("Yes\n");            continue;        }        else if(cnt == 2){            int t1 = 0, t2 = 0;            for(int i = 3; i <= 17; ++i){                if(Hash1[i] > 0){                    if(t1 == 0){                        t1 = i;                    }                    else {                        t2 = i;                    }                }            }            if(Hash1[t1] == 3 && Hash1[t2] == 1){                printf("Yes\n");                continue;            }            if(Hash1[t2] == 3 && Hash1[t1] == 1){                printf("Yes\n");                continue;            }            if(Hash1[t1] == 3 && Hash1[t2] == 2){                printf("Yes\n");                continue;            }            if(Hash1[t2] == 3 && Hash1[t1] == 2){                printf("Yes\n");                continue;            }            if(Hash1[t1] == 4 && Hash1[t2] == 2){                printf("Yes\n");                continue;            }            if(Hash1[t2] == 4 && Hash1[t1] == 2){                printf("Yes\n");                continue;            }        }        else if(cnt == 3){            int t1 = 0, t2 = 0, t3 = 0;            for(int i = 3; i <= 17; ++i){                if(Hash1[i] > 0){                    if(t1 == 0){                        t1 = i;                    }                    else if(t2 == 0){                        t2 = i;                    }                    else {                        t3 = i;                    }                }            }            if(Hash1[t1] == 4 && Hash1[t2] == 1 && Hash1[t3] == 1){                printf("Yes\n");                continue;            }            else if(Hash1[t1] == 1 && Hash1[t2] == 4 && Hash1[t3] == 1){                printf("Yes\n");                continue;            }            else if(Hash1[t1] == 1 && Hash1[t2] == 1 && Hash1[t3] == 4){                printf("Yes\n");                continue;            }        }        if(Hash2[16] == 1 && Hash2[17] == 1){            printf("No\n");            continue;        }        bool flag = false;        ///bomb        for(int i = 15; i >= 3; --i){            if(Hash1[i] == 4){                int j;                for(j = i+1; j <= 15; ++j){                    if(Hash2[j] == 4){                        break;                    }                }                if(j == 16){                    flag = true;                }            }        }        if(flag){            printf("Yes\n");            continue;        }        ///Four-Dual        for(int i = 15; i >= 3; --i){            if(Hash1[i] == 4 && len1 >= 6){                int j;                for(j = i+1; j <= 15; ++j){                    if(Hash2[j] == 4 && len2 >= 6){                        break;                    }                }                int k;                for(k = 3; k <= 15; ++k){                    if(Hash2[k] == 4){                        break;                    }                }                if(j == 16 && k == 16){                    flag = true;                    //printf("Four-Dual\n");                }            }        }        if(flag){            printf("Yes\n");            continue;        }        ///Trio-Pair        for(int i = 15; i >= 3; --i){            if(Hash1[i] == 3){                for(int j = 3; j <= 15; ++j){                    if(Hash1[j] == 2){                        int k;                        int t = 0;                        for(k = i+1; k <= 15; ++k){                            if(Hash2[k] == 3){                                for(int l = 3; l <= 15; ++l){                                    if(Hash2[l] == 2){                                        t = 1;                                        break;                                    }                                }                                if(t == 1){                                    break;                                }                            }                        }                        int p;                        for(p = 3; p <= 15; ++p){                            if(Hash2[p] == 4){                                break;                            }                        }                        if(k == 16 && p == 16){                            flag = true;                            //printf("Trio-Pair\n");                        }                    }                }            }        }        if(flag){            printf("Yes\n");            continue;        }        ///Trio-Solo        for(int i = 15; i >= 3; --i){            if(Hash1[i] == 3 && len1 >= 4){                int j;                for(j = i+1; j <= 15; ++j){                    if(Hash2[j] == 3 && len2 >= 4){                        break;                    }                }                int k;                for(k = 3; k <= 15; ++k){                    if(Hash2[k] == 4){                        break;                    }                }                if(j == 16 && k == 16){                    flag = true;                    //printf("Trio-Solo\n");                }            }        }        if(flag){            printf("Yes\n");            continue;        }        ///Trio        for(int i = 15; i >= 3; --i){            if(Hash1[i] == 3){                int j;                for(j = i+1; j <= 15; ++j){                    if(Hash2[j] >= 3){                        break;                    }                }                int k;                for(k = 3; k <= 15; ++k){                    if(Hash2[k] == 4){                        break;                    }                }                if(j == 16 && k == 16){                    flag = true;                    //printf("Trio\n");                }            }        }        if(flag){            printf("Yes\n");            continue;        }        ///Pair        for(int i = 15; i >= 3; --i){            if(Hash1[i] == 2){                int j;                for(j = i+1; j <= 15; ++j){                    if(Hash2[j] >= 2){                        break;                    }                }                int k;                for(k = 3; k <= 15; ++k){                    if(Hash2[k] == 4){                        break;                    }                }                if(j == 16 && k == 16){                    flag = true;                    //printf("Pair\n");                }            }        }        if(flag){            printf("Yes\n");            continue;        }        ///Solo        for(int i = 17; i >= 3; --i){            if(Hash1[i] == 1){                int j;                for(j = i+1; j <= 17; ++j){                    if(Hash2[j] >= 1){                        break;                    }                }                int k;                for(k = 3; k <= 15; ++k){                    if(Hash2[k] == 4){                        break;                    }                }                if(j == 18 && k == 16){                    flag = true;                    //printf("Solo\n");                }            }        }        if(flag){            printf("Yes\n");            continue;        }        printf("No\n");    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.