zoukankan      html  css  js  c++  java
  • UVA

    link

    Input

    The input consists of at most 50 test cases. Each case consists of 13 tiles in a single line. The hand is
    legal (e.g. no invalid tiles, exactly 13 tiles). The last case is followed by a single zero, which should not
    be processed.
    Output
    For each test case, print the case number and a list of waiting tiles sorted in the order appeared in
    the problem description (1T~9T, 1S~9S, 1W~9W, DONG, NAN, XI, BEI, ZHONG, FA, BAI). Each waiting tile
    should be appeared exactly once. If the hand is not ready, print a message `Not ready' without quotes.
    Sample Input
    1S 1S 2S 2S 2S 3S 3S 3S 7S 8S 9S FA FA
    1S 2S 3S 4S 5S 6S 7S 8S 9S 1T 3T 5T 7T
    0
    Sample Output
    Case 1: 1S 4S FA
    Case 2: Not ready

    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    
    int c[34];
    const char *ma[] = {"1T", "2T", "3T", "4T", "5T", "6T", "7T", "8T", "9T", "1S", "2S", "3S", "4S", "5S", "6S", "7S",
                        "8S", "9S", "1W", "2W", "3W", "4W", "5W", "6W", "7W", "8W", "9W", "DONG", "NAN", "XI", "BEI",
                        "ZHONG", "FA", "BAI"};
    
    int convert(char *s);
    
    bool check(int i);
    
    int main() {
        char s[100];
        for (int base = 1; scanf("%s", s);) {
            bool ok = false;
            if (s[0] == '0')
                break;
            printf("Case %d:", base++);
            memset(c, 0, sizeof(c));
            c[convert(s)]++;
            for (int i = 1; i < 13; ++i) {
                scanf("%s", s);
                c[convert(s)]++;
            }
    
            for (int i = 0; i < 34; ++i) {
                if (c[i] >= 4)
                    continue;
                c[i]++;
                for (int j = 0, p = 0; j < 34; ++j) { //找将
                    if (c[j] >= 2) {
                        c[j] -= 2;
                        p = check(0);
                        c[j] += 2;
                        if (p) {
                            ok = 1;
                            printf(" %s", ma[i]);
                            break;
                        }
                    }
                }
                c[i]--;
            }
            if (!ok)
                printf(" Not ready");
            printf("
    ");
        }
    }
    
    bool check(int h) {
        if (h == 4)
            return true;
        for (int i = 0; i < 34; ++i) { //刻子
            if (c[i] >= 3) {
                c[i] -= 3;
                bool p = check(h + 1);
                c[i] += 3;
                if (p) return true;
            }
            if (i < 27 and i % 9 < 7 and c[i] > 0 and c[i + 1] > 0 and c[i + 2] > 0) {//顺子
                for (int t = 0; t < 3; ++t) c[i + t]--;
                bool p = check(h + 1);
                for (int t = 0; t < 3; ++t) c[i + t]++;
                if (p) return true;
            }
        }
        return false;
    }
    
    int convert(char *s) {
        for (int i = 0; i < 34; ++i) {
            if (!strcmp(s, ma[i]))
                return i;
        }
        return -1;
    }
  • 相关阅读:
    IE10、IE11下SCRIPT5009: “__doPostBack”未定义
    CSS Hack大全-可区分出IE6-IE10、FireFox、Chrome、Opera
    HTML head 头标签
    html5匹配不同分辨率样式
    html5关键帧动画,一个小例子快速理解关键帧动画
    导入Excel到数据库
    JavaScript树(一) 简介
    深入解析浏览器的幕后工作原理(五) 呈现树
    深入解析浏览器的幕后工作原理(四) DOM树
    深入解析浏览器的幕后工作原理(三) 呈现树和 DOM 树的关系
  • 原文地址:https://www.cnblogs.com/wangsong/p/7529210.html
Copyright © 2011-2022 走看看