Programming thinking week6 limited time simulation

topic

Dongdong has A × B playing cards. Each playing card has a size (integer, a, range 0 to A-1) and a suit (integer, b), range 0 to B-1.
Playing cards are different, also It is unique, that is to say, no two cards are the same size and suit.
"One hand" means that you have 5 different cards in your hand. These 5 cards are not in the order of who is in front and who is behind. They can form a card type. We have defined 9 card types. The following are the rules of 9 card types. We use "low serial number priority" to match the card types, that is, the "first hand" meets the first from the top. A card type rule is its "card number" (an integer, from 1 to 9):
Straight flush: Rule 5 and rule 4 are both met.
Bomb: 5 cards of which 4 cards are the same size.
Three belts two: Among the 5 cards, 3 of them are the same size, and the other 2
are of the same
size . Straight: 5 cards are of the same suit. Straight: 5 cards of the same size as x, x + 1, x + 2, x + 3, x + 4
three: 5 cards which is equal to the size of three cards.
two pairs: 5 cards which is equal to the size of two cards, Further card 2 is equal to three card size.
One pair: 5 cards which is equal to the size of two cards.
To afford: the hand does not satisfy any of a card type.
Now, from Eastern A × 2 cards were taken from the B playing cards! They are (a1, b1) and (a2, b2). (Where a is the size and b is the suit)
Now we will randomly take out the remaining cards 3 cards! Form a hand card !!!
In fact, in addition to playing codes, Dongdong is still a magician in his spare time. Now he wants to predict the possibility of his future, that is, the possibility of the "first hand" he will get. , Belonging to 1 to 9) "to indicate the hand type of this hand, then he has 9 possibilities in the future, but the number of each possible scheme is different.

Input

Line 1 contains integers A and B (5 ≤ A ≤ 25, 1 ≤ B ≤ 4).
Line 2 contains integers a1, b1, a2, b2 (0 ≤ a1, a2 ≤ A-1, 0 ≤ b1 , b2 ≤ B-1, (a1, b1) ≠ (a2, b2)).

Output

A line is output. There are 9 integers in this line, and each integer represents the number of schemes of 9 card types (in order of card number from small to large).

Sample Input

5 2
1 0 3 1

Sample Ouput

0 0 0 0 8 0 12 36 0

Ideas

The type of cards is 4 * 25 = 100 at most, and the amount of data is small. Choose 3 cards in a direct three-layer loop with a complexity of O (n 3 ), which is acceptable.
Add all the card types (except the two given) to the array of structure card. The three-layer loop of the array selects three cards and judges the card type of a hand.
In order to compare the size of the cards, makeOrdered cards. After the 5 cards are ordered, you only need to compare the size of the cards in the special position to determine the card type. For example, ifNumber 0 and Number 3Of the same size orNumber 1 and Number 4Is the same size asbomb

Code

#include <cstdio>
#include <algorithm>
using namespace std;
struct card{
    int suit,val;
    card& operator=(card c){suit=c.suit;val=c.val;return *this;}
    bool operator==(card c){return suit==c.suit&&val==c.val;}
    bool operator<(card c)const{return val!=c.val?val<c.val:suit<c.suit;}
}c[105],tmp[6];
int sum[10];
int A,B;

void judge(){
    bool flags=true,flagv=true;
    for(int i=0;i<4;i++){
        if(tmp[i+1].val-tmp[i].val!=1)
            flagv=false;
        if(tmp[i+1].suit!=tmp[i].suit)
            flags=false;
    }
    if(flags&&flagv)//同花顺
        sum[1]++;
    else if(flags)//同花
        sum[4]++;
    else if(flagv)//顺子
        sum[5]++;
    else{
        if((tmp[0].val==tmp[3].val)||(tmp[1].val==tmp[4].val))//炸弹
            sum[2]++;
        else if((tmp[0].val==tmp[1].val&&tmp[2].val==tmp[4].val)||(tmp[0].val==tmp[2].val&&tmp[3].val==tmp[4].val))//三带二
            sum[3]++;
        else if(tmp[0].val==tmp[2].val||tmp[2].val==tmp[4].val||tmp[1].val==tmp[3].val)//三条
            sum[6]++;
        else if(tmp[0].val==tmp[1].val&&tmp[2].val==tmp[3].val)//两对
            sum[7]++;
        else if(tmp[0].val==tmp[1].val&&tmp[3].val==tmp[4].val)//两对
            sum[7]++;
        else if(tmp[1].val==tmp[2].val&&tmp[3].val==tmp[4].val)//两对
            sum[7]++;
        else{
            bool flag=false;
            for(int i=0;i<4;i++){
                if(tmp[i+1].val==tmp[i].val)
                    flag=true;
            }
            if(flag)
                sum[8]++;
            else sum[9]++;
        }
    }
}

int main(){
    memset(sum, 0, sizeof(sum));
    scanf("%d%d",&A,&B);
    int a1,b1,a2,b2;
    scanf("%d%d%d%d",&a1,&b1,&a2,&b2);
    int k=0;
    for(int i=0;i<A;i++){
        for(int j=0;j<B;j++){
            if(!(i==a1&&j==b1)&&!(i==a2&&j==b2)){
                c[k].val=i;c[k].suit=j;
                k++;
            }
        }
    }
    for(int i=0;i<k;i++){
        for(int j=i+1;j<k;j++){
            for(int m=j+1;m<k;m++){
                tmp[0].val=a1;tmp[0].suit=b1;
                tmp[1].val=a2;tmp[1].suit=b2;
                tmp[2]=c[i];
                tmp[3]=c[j];
                tmp[4]=c[m];
                sort(tmp,tmp+5);
                judge();
            }
        }
    }
    for(int i=1;i<=9;i++)
        printf("%d ",sum[i]);
    return 0;
}

to sum up

At first I thought about recursive enumeration, but obviously I won't. .
Title link

Published 24 original articles · praised 2 · visits 435

Guess you like

Origin blog.csdn.net/weixin_43805228/article/details/105281607