山东大学程序设计思维-每月复杂模拟1-飞飞的赌神修炼手册

#include<bits/stdc++.h>
using namespace std;
int cnt[11];
struct card{
    int a;
    int b;
    bool operator<(card c){
        if(a<c.a) return true;
        if(a>c.a) return false;
        if(b<c.b) return true;
        if(b>c.b) return false;
    }
    bool operator==(card c){
        if(a==c.a&&b==c.b) return true;
        return false;
    }
    card(int aa,int bb){
        a=aa;b=bb;
    }
    card(){};
};
vector<card> hold;
bool bomb(){
    //判断炸弹
    if(hold[0].a==hold[1].a){
        for(int i=0;i<3;i++){
            if(hold[i+1].a!=hold[i].a) return false;
        }
    }
    else{
        for(int i=1;i<4;i++){
            if(hold[i+1].a!=hold[i].a) return false;
        }
    }
    return true;
}
bool three_two(){
    //判断三带二
    //2 2 2 3 3
    //2 2 3 3 3
    if(hold[1].a!=hold[2].a){
        if(hold[0].a!=hold[1].a) return false;
        if(hold[2].a!=hold[3].a) return false;
        if(hold[3].a!=hold[4].a) return false;
        return true;
    }
    else{
        if(hold[0].a!=hold[1].a) return false;
        if(hold[3].a!=hold[4].a) return false;
        return true;
    }
    return false;
}
bool sameb(){
    //判断同花
    for(int i=0;i<4;i++){
        if(hold[i+1].b!=hold[i].b) return false;
    }
    return true;
}
bool straight(){
    //判断顺子
    for(int i=0;i<4;i++){
        if(hold[i+1].a!=hold[i].a+1) return false;
    }
    return true;
}
bool sameb_straight(){
    //判断同花顺
    if(sameb()&&straight()) return true;
    return false;
}
bool three(){
    //判断三条
    if(hold[0].a==hold[1].a){
        if(hold[1].a==hold[2].a) return true;
    }
    if(hold[1].a==hold[2].a){
        if(hold[2].a==hold[3].a) return true;
    }
    if(hold[2].a==hold[3].a){
        if(hold[3].a==hold[4].a) return true;
    }
    return false;
}
bool double_two(){
    //判断两对
    if(hold[0].a==hold[1].a){
        if(hold[2].a==hold[3].a) return true;
    }
    if(hold[1].a==hold[2].a){
        if(hold[3].a==hold[4].a) return true;
    }
    if(hold[0].a==hold[1].a){
        if(hold[3].a==hold[4].a) return true;
    }
    return false;
}
bool two(){
    //判断一对
    if(hold[0].a==hold[1].a) return true;
    if(hold[1].a==hold[2].a) return true;
    if(hold[2].a==hold[3].a) return true;
    if(hold[3].a==hold[4].a) return true;
    return false;
}
void valirify(){
    if(sameb_straight()){
        cnt[0]++;
        return;
    }
    if(bomb()){
        cnt[1]++;
        return;
    }
    if(three_two()){
        cnt[2]++;
        return;
    }
    if(sameb()){
        cnt[3]++;
        return;
    }
    if(straight()){
        cnt[4]++;
        return;
    }
    if(three()){
        cnt[5]++;
        return;
    }if(double_two()){
        cnt[6]++;
        return;
    }
    if(two()){
        cnt[7]++;
        return;
    }
    cnt[8]++;
}
card pool[110];
int main(){
    memset(cnt,0,sizeof(cnt));
    int anum,bnum;
    int step=0;
    cin>>anum>>bnum;
    int sum=anum*bnum;
    card start1,start2;
    cin>>start1.a>>start1.b>>start2.a>>start2.b;
    hold.push_back(start1);
    hold.push_back(start2);
    for(int i=0;i<anum;i++){
        for(int j=0;j<bnum;j++){
            if((i==start1.a&&j==start1.b)||(i==start2.a&&j==start2.b)) continue;
            card temp(i,j);
            pool[step++]=temp;
        }
    }
    for(int i=0;i<sum-2;i++){
        hold.push_back(pool[i]);
        for(int j=0;j<i;j++){
            hold.push_back(pool[j]);
            for(int k=0;k<j;k++){
                hold.push_back(pool[k]);
                sort(hold.begin(),hold.end());
                valirify();
                for(auto it=hold.begin();it!=hold.end();it++){
                    if(*it==pool[k]){
                        hold.erase(it);
                        break;
                    }
                }
            }
            for(auto it=hold.begin();it!=hold.end();it++){
                if(*it==pool[j]){
                    hold.erase(it);
                    break;
                }
            }
        }
        for(auto it=hold.begin();it!=hold.end();it++){
            if(*it==pool[i]){
                hold.erase(it);
                break;
            }
        }
    }
    for(int i=0;i<9;i++) cout<<cnt[i]<<' ';
    return 0;
}

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值