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;
    }
  • 相关阅读:
    网络知识
    DXP 技巧和龙芯3A装机
    312-金胜维 P系列2.5寸 480G SATA3 SSD固态硬盘
    NVIDIA Jetson TK1 开发板
    NVIDIA Jetson™ TX1
    XILINX FPGA 开发板 XC3S250E 核心板 学习板+12模块
    AES-OZ745 OZ745 Zynq-7000 开发板与套件
    北京太速科技——海外代购
    AR/VR增强现实 虚拟现实,嵌入式解决方案探讨
    270-VC709E 增强版 基于FMC接口的Xilinx Vertex-7 FPGA V7 XC7VX690T PCIeX8 接口卡
  • 原文地址:https://www.cnblogs.com/wangsong/p/7529210.html
Copyright © 2011-2022 走看看