CSP3魔法のマスター

問題の説明

Ruishenのカードゲームから戻った後、Dongdongは苦痛を感じ、彼のカードスキルを練習することに決め、最終的にギャンブラーになりました!
東洞にはA×Bのトランプがあります。各トランプには、サイズ(整数、a、範囲0〜A-1)とスーツ(整数、b)、範囲
0〜B -1があります。トランプも異なります。これはユニークです。つまり、同じサイズで同じカードが2枚ない
ことです「片手」とは、5枚のカードを手に持っていることを意味しますこれらの5枚のカードは、誰が誰の前にいるかという順序ではありません。カードタイプを形成できます。9種類のカードタイプを定義しました。以下は9種類のカードタイプのルールです。「低いシリアル番号の優先順位」を使用してカードタイプを一致させます。つまり、「最初の手」が最初から最初に出会います。カードタイプルールは、その「カード番号」(1から9までの整数)です:
1.ストレートフラッシュ:ルール5とルール4の両方が満たされています
2.爆弾:5枚中4枚のカードのサイズは同じです。
3. 3本のベルトと2本:5枚のカード(そのうち3枚は同じサイズ)と他の2枚のカードも同じサイズ
4.ストレート:5枚のカードが同じスーツ
5.ストレート:5枚のカードサイズはx、x + 1、x + 2、x + 3、x + 4
6、3のようです:3枚:5枚のカード、3枚は同じサイズ
。7、2ペア:5枚のカード その中で、2枚のカードは同じサイズで、他の3枚のカードのうち2枚は同じサイズです
。8。ペア:5枚のカード、そのうち2枚は同じサイズです
。9 余裕がありません:このハンドでは不十分です上記のカードのいずれかです。
今、ドンドンはA×Bのトランプから2枚のカードを取ります!(a1、b1)と(a2、b2)です(aはサイズ、bはスーツです) )
次に、残りのトランプからランダムに3枚のカードを抽選する必要があります!
実際、コードをプレイすることに加えて、ドンドンは余暇にはまだ魔術師です。今、彼は彼の将来の可能性、つまり彼が得る「最初の手」の可能性を予測したいと考えています。「カード番号(整数、1から9まで)「このハンドのハンドタイプを示すために、彼には将来9通りの可能性がありますが、可能な各スキームの数は異なります。
これで、ドンドンのアゴモの目はなくなりました。アゴモが9種類それぞれのオプションの数を数えるのを手伝う必要があります。入力
行1には整数AおよびBが含まれます(5≤A≤25、1≤B≤4)。行2には整数a1、b1、a2、b2(0≤a1、a2≤A-1、0≤が含まれます。 b1、b2≤B-1、(a1、b1)≠(a2、b2))出力は1行に
出力され
ますこの行には9つの整数があり、各整数は9つのカードタイプのスキームの数を表します(小からのカード番号によると)大きい順)

样例:
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
アイデア

構造体のpai変数を使用してカードを表し、nとmに従ってすべてのカードをリストし、それらを配列allに格納してから、手にある2枚のカードをhand配列に入れ、残りの3つのチケットの考えられるすべての条件をリストします。 、どちらのフォームがケースごとに判断され、判断フォームは関数fun()で実装されます。
fun()については、手札の同じ枚数による9種類の判断で5種類あることがわかりますので、計算を容易にするため、カードの種類や順番は関係ないため、同じ値を個別に返す関数を書いてください、最初にhand配列を並べ替えることができるので、1回のトラバースで同じ数の判断を行うことができます。equalsのセットが複数ある場合は、より大きい数が返されます。ストレートかフラッシュかを判断することもワンパスで行えます。
bool h = hua()、s = shun(); int b = same();
さまざまなタイプの判定条件:
1.ストレートフラッシュ、h && sがtrueである必要がある
2.爆弾:b == 4
3. 3つのベルト2:
(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、フラッシュ:hはtrue
5、ストレート: sはtrue
6、3:b == 3 7、2
つのペア: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.ペア:b == 2
9.できること:その他

コード
#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;
}
まとめ

最初は先輩からの期待通り、回り道をして、数学の問題のアイデアに合わせてアレンジして、プログラミング、ああ、食べ物は無視しました!

元の記事を20件公開 賞賛3件 訪問452件

おすすめ

転載: blog.csdn.net/qq_44893580/article/details/105313655