CSP3 Master of magic

Problem Description

After returning from the card game of Ruishen, Dongdong felt painful and decided to practice his card skills, and eventually became a gambler!
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):
1. Straight flush: Rule 5 and rule 4 are both met.
2. Bomb: 4 of 5 cards are equal in size.
3. Three belts and two: 5 cards, 3 of which are equal in size, and the other 2 cards are also equal in size.
4. Straight: 5 cards are of the same suit.
5. Straight: 5 cards The size is like x, x + 1, x + 2, x + 3, x + 4
6, three: 5 cards, 3 of which are the same size.
7, two pairs: 5 cards Among them, 2 cards are the same size, and 2 of the other 3 cards are the same size.
8. Pair: 5 cards, 2 of which are the same size.
9. I ca n’t afford it: This hand is not enough Any one of the above cards.
Now, Dongdong takes 2 cards from the A × B playing cards! They are (a1, b1) and (a2, b2). (Where a is the size and b is the suit )
Now we have to randomly draw 3 more cards from the remaining playing cards!
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. We use a "card number (an integer , 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.
Now, Dong Dong ’s eye of Agomo is gone. You need to help him count the number of options for each of the 9 types. 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
output a line, this line has 9 integers, each integer represents the number of schemes of 9 card types (according to the card number from small To big order)

样例:
Input
5 2
1 0 3 1
Output
0 0 0 0 8 0 12 36 0
Input
25 4
0 0 24 3
Output
0 2 18 0 0 644 1656 36432 113344
Ideas

Use a structure pai variable to represent the cards, list all the cards according to n and m, store them in the array all, then put the two cards in the hand into the hand array, and then list all the possible conditions of the remaining three tickets , Which form is judged for each case, and the judgment form is implemented in the function fun ().
For fun (), we observe that there are 5 types in the 9 forms of judgment according to the same number of cards in the hand, so write a function that returns the same value separately, because the type and the order of the cards are irrelevant, in order to facilitate calculation , We can first sort the hand array, so that the same number of judgments can be achieved by traversing once, and when there are multiple sets of equals, the larger number is returned. Judging whether it is straight or flush can also be done in one pass.
Use bool h = hua (), s = shun (); int b = same ();
Various types of judgment conditions:
1. Straight flush, need h && s to be true
2. Bomb: b == 4
3. Three belts two:
(hand [0] .no == hand [1] .no && hand [2] .no == hand [3] .no & & hand [3] .no == hand [4] .no) || (hand [0] .no == hand [1] .no && hand [1] .no == hand [2] .no && hand [3] .no == hand [4] .no)
4, flush: h is true
5, straight: s is true
6, three: b == 3
7, two pairs: b == 2 && ((hand [0] .no == hand [1] .no && hand [2] .no == hand [3] .no)
|| (hand [0] .no == hand [1] .no && hand [4] .no == hand [2].
(hand[0].no== hand[1].no&&hand[3].no== hand[4].no)
||(hand[0].no== hand[2].no&&hand[3].no== hand[4].no)
||(hand[1].no== hand[2].no&&hand[3].no== hand[4].no)))

8. A pair: b == 2
9. Able to: else

Code
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct pai
{
    int no,h;
    bool operator<(const pai&a)const{
        return no==a.no?h<a.h:no<a.no;
    }
};
pai hand[5],all[111];
int n,m,cnt,ans[9],a1,a2,b1,b2;
bool hua()
{
    if(hand[0].h==hand[1].h&&hand[1].h==hand[2].h&&hand[2].h==hand[3].h&&hand[3].h==hand[4].h)
    return 1;
    return 0;
}
bool shun()
{
    if(hand[1].no==hand[0].no+1&&hand[2].no==hand[1].no+1&&hand[3].no==hand[2].no+1&&hand[4].no==hand[3].no+1)
    return 1;
    return 0;
}
int same()
{
    int cont=1,max=1,pre=hand[0].no;
    for(int i=1;i<5;i++)
    {
        if(hand[i].no==pre)
        {
            cont++;
        }
        else
        { 
            if(cont>max)max=cont;
            cont=1;
            pre=hand[i].no;
        }
        
    }
    if(cont>max)max=cont;//最后一次
    return max;
}
void fun()
{
    bool h=hua(),s=shun();
    if(h&&s)
    {
        ans[0]++;return;
    }    
    int b=same();

    if(b==4)
    {
        ans[1]++;return;
    }
    //三带二
    if((hand[0].no==hand[1].no&&hand[2].no==hand[3].no&&hand[3].no==hand[4].no)
    ||(hand[0].no==hand[1].no&&hand[1].no==hand[2].no&&hand[3].no==hand[4].no))
    {
        ans[2]++;return;
    }
    if(h)
    {
        ans[3]++;return;
    }
    if(s)
    {
        ans[4]++;return;
    }
    if(b==3)
    {
        ans[5]++;return;
    }
    if(b==2&&((hand[0].no==hand[1].no&&hand[2].no==hand[3].no)
    ||(hand[0].no==hand[1].no&&hand[4].no==hand[2].no)||
    (hand[0].no==hand[1].no&&hand[3].no==hand[4].no)
    ||(hand[0].no==hand[2].no&&hand[3].no==hand[4].no)
    ||(hand[1].no==hand[2].no&&hand[3].no==hand[4].no)))
    {
        ans[6]++;return;
    }
    if(b==2)
    {
        ans[7]++;return;
    }
    ans[8]++;
    
}
int main()
{
    scanf("%d%d",&n,&m);
    scanf("%d%d%d%d",&hand[0].no,&hand[0].h,&hand[1].no,&hand[1].h);
    a1=hand[0].no;
    a2=hand[0].h;
    b1=hand[1].no;
    b2=hand[1].h;
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    {
        if ((i==a1&&j==a2)||(i==b1&&j==b2))  continue;
        all[cnt].no=i;all[cnt++].h=j;
    }
   // printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    for(int j=i+1;j<cnt;j++)
    for(int l=j+1;l<cnt;l++)
    { 
        hand[0].no=a1;
        hand[0].h=a2;
        hand[1].no=b1;
        hand[1].h=b2;
        hand[2]=all[i];
        hand[3]=all[j];
        hand[4]=all[l];
        sort(hand,hand+5);  
        fun();
    }
    for(int i=0;i<9;i++)
    printf("%d\n",ans[i]);
    //system("pause");
    return 0;
}
to sum up

At first, as expected by the seniors, I took a detour, arranged and combined according to the ideas of mathematics questions, and ignored the programming, alas, food! ! !

Published 20 original articles · praised 3 · visits 452

Guess you like

Origin blog.csdn.net/qq_44893580/article/details/105313655