zoukankan      html  css  js  c++  java
  • 2014 HDU多校弟六场J题 【模拟斗地主】

    这是一道5Y的题目

    有坑的地方我已在代码中注释好了 QAQ 

    Ps:模拟题还是练的太少了,速度不够快诶

    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
    #include <stdio.h>
    #include <iostream>
    #include <climits>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <vector>
    #include <algorithm>
    #define ll long long
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int MAXN = 1001;
    
    char array_a[30], array_b[30];
    int store_a[16], store_b[16];
    char rules[16];
    bool ans;
    
    int find_rank(char num){
        for(int i = 1; i <= 15; ++i){
            if(rules[i] == num){
                return i;
            }
        }
    }
    
    void init(){
        ans = false;
        rules[1] = '3', rules[2] = '4', rules[3] = '5', rules[4] = '6';
        rules[5] = '7', rules[6] = '8', rules[7] = '9', rules[8] = 'T';
        rules[9] = 'J', rules[10] = 'Q', rules[11] = 'K', rules[12] = 'A';
        rules[13] = '2', rules[14] = 'X', rules[15] = 'Y';
    
        memset(store_a, 0, sizeof(store_a));
        memset(store_b, 0, sizeof(store_b));
        for(int i = 0; i < strlen(array_a); ++i)
            ++store_a[find_rank(array_a[i])];
        for(int i = 0; i < strlen(array_b); ++i)
            ++store_b[find_rank(array_b[i])];
    }
    
    bool lose(){
        int i, j;
        if(store_b[14] == 1 && store_b[15] == 1)    return true;
        for(i = 1; i <= 13; ++i)
            if(store_b[i] == 4) return true;
        return false;
    }
    
    bool way_2(){
        int i, j;
        int get_a_max, get_b_max;
        if(lose())  return false;
        for(i = 15; i >= 1; --i){
            if(store_a[i]){
                get_a_max = i;
                break;
            }
        }
        for(i = 15; i >= 1; --i){
            if(store_b[i]){
                get_b_max = i;
                break;
            }
        }
        if(get_a_max >= get_b_max)  return true;
        return false;
    }
    
    bool way_3(){
        int i, j;
        if(store_a[14] == 1 && store_a[15] == 1)    return true;
        if(way_2()) return true;
        if(lose())  return false;
        int get_a_max, get_b_max;
        get_a_max = get_b_max = 0;//get_*_max init 0
        for(i = 13; i >= 1; --i){
            if(store_a[i] == 2){
                get_a_max = i;
                break;
            }
        }
        for(i = 13; i >= 1; --i){
            if(store_b[i] == 2){
                get_b_max = i;
                break;
            }
        }
        if(get_a_max == 0)  return false;//if get_*_max is still 0 , return false
        else if(get_a_max >= get_b_max)  return true;
        return false;
    }
    
    bool way_4(){
        int i, j;
        if(way_3()) return true;
        if(lose())  return false;
    
        int get_a_max, get_b_max;
        get_a_max = get_b_max = 0;//
        for(i = 13; i >= 1; --i){
            if(store_a[i] == 3){
                get_a_max = i;
                break;
            }
        }
        for(i = 13; i >= 1; --i){
            if(store_b[i] == 3){
                get_b_max = i;
                break;
            }
        }
        if(get_a_max == 0)  return false;//
        else if(get_a_max >= get_b_max)  return true;
        return false;
    }
    
    bool way_5(){
        int i, j;
        if(way_4()) return true;
        if(store_b[14] == 1 && store_b[15] == 1)    return false;
    
        int num_a = 0, num_b = 0;
        for(i = 1; i <= 15; ++i){
            if(store_a[i] >= 4){
                num_a = i;
                break;
            }
        }
        for(i = 1; i <= 15; ++i){
            if(store_b[i] >= 4){
                num_b = i;
                break;
            }
        }
        if(num_a == 0)  return false;
        else if(num_a >= num_b)  return true;
        return false;
    }
    
    bool way_6(){
        int i, j;
        if(way_5()) return true;
        if(store_b[14] == 1 && store_b[15] == 1)    return false;
    
        return false;
    }
    
    bool first_out(){
        int count = 0;
        int i, j, k;
        for(i = 1; i <= 15; ++i){
            if(store_a[i])  count += store_a[i];
        }
        if(0 == count){
            return true;
        } else if(1 == count){
            return true;
        } else if(2 == count){
            if(store_a[14] == 1 && store_a[15] == 1){
                return true;
            } else{
                for(i = 1; i <= 13; ++i){
                    if(store_a[i] == 2){
                        return true;
                    }
                }
    
                if(way_2()) return true;
                return false;
            }
        } else if(3 == count){
            for(i = 1; i <= 13; ++i){
                if(store_a[i] == 3){
                    return true;
                }
            }
    
    
            if(way_3()) return true;
            return false;
        } else if(4 == count){
            for(i = 1; i <= 15; ++i){
                if(store_a[i] >= 3){
                    return true;
                }
            }
    
            if(way_4()) return true;
            return false;
        } else if(5 == count){
            int count_a = 0, count_b = 0;
            for(i = 1; i <= 15; ++i){
                if(store_a[i] == 3) ++count_a;
                else if(store_a[i] == 2 && i <= 13) ++count_b;
            }
            if(count_a && count_b){
                return true;
            }
    
            if(way_5()) return true;//
            return false;
        } else if(6 == count){
            int count_a = 0;
            for(i = 1; i <= 15; ++i){
                if(store_a[i] == 4) ++count_a;
            }
            if(count_a){
                return true;
            }
    
            if(way_6()) return true;//
            return false;
        }
    
        if(way_6()) return true;
        return false;
    }
    
    void debug(){
        for(int i = 1; i <= 15; ++i){
            printf("%-2d", store_a[i]);
        }
        printf("
    ");
        for(int i = 1; i <= 15; ++i){
            printf("%-2d", store_b[i]);
        }
        printf("
    ");
    }
    
    int main(){
        int i, j, k, numCase;
        scanf("%d",&numCase);
        while(numCase--){
            scanf("%s",array_a);
            scanf("%s",array_b);
            init();
            //debug();
            if(first_out()){
                printf("Yes
    ");
            } else{
                printf("No
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    矢量坐标矩阵 为了方便求叉乘
    力矩 是形容物理转动效果的量
    科式力 河流右边冲刷严重
    科式力
    证明科式力 coriolis acceleration
    叉乘的求导证明
    spring webFlux的认识
    [转] DB2错误代码说明
    MySQL事务及其实现
    MySQL基础架构之查询语句执行流程
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/3902867.html
Copyright © 2011-2022 走看看