UVa 11210 Chinese Mahjong (violence, recursive search)

Source: Internet
Author: User

Test instructions: This test instructions. A bit of a hassle, that is, given 13 cards, you can ask for "Listen" cards. (See the original question for details)

Original title Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=2151

Analysis: See this question, really trouble ah, I do not understand Mahjong, looked at a long time to understand what is "listening." Analyze the idea.

First of all the cards are numbered, and then violence, the first is to determine which is to be, and then further judgment,

Which one is carved, flush, with recursion is very simple, as long as the full search is good. The whole is not difficult, easy to understand.

Note that there are four cards, you can no longer "listen", this is a pit.

The code is as follows:

#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include < cmath>using namespace Std;const int maxn = 2T + 5;const char *mahjong[] = {"1T", "", "3T", "4T", "5T", "6T", "7T" , "8T", "9T", "1S", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "1W", "2W", "3W", "4W", "5W", "6W", "9W", "Dong", "NAN", "XI", "BEI", "ZHONG", "FA", "BAI"};//play a Mahjong table int c[35], Id[15];char s[100];int getid (const char *s    {//Get ID for each card for (int i = 0; i < ++i) if (!strcmp (Mahjong[i], s)) return i; return-1;} BOOL Dfs (int d) {for (int i = 0; i < ++i) if (C[i] > 2) {//engraved if (3 = = d) return true;//except will, then the flush of the engraved and should be 4        One, so this has been judged unharmed. C[i]-= 3;  if (Dfs (d+1)) {C[i] + = 3; return true;    }//find, should pay attention to the c[i] [c[i] + = 3; } for (int i = 0; i < ++i) if (i% 9 <= 6 && C[i] > 0 && c[i+1] > 0 && c[i +2] > 0) {//CIS if (3 = = d) return True;//Ibid.--c[i];  --C[I+1];            --C[I+2];  if (Dfs (d+1)) {++c[i];  ++C[I+1];  ++C[I+2]; return true;  }//ibid. ++c[i];  ++C[I+1];        ++C[I+2]; } return false;}            BOOL Judge () {for (int i = 0; i <; ++i) if (C[i] > 1) {//violence, a single piece of judgment, is not c[i]-= 2;//judgment is going to be  if (Dfs (0)) {C[i] + = 2; return true;    }//set up, to change c[i] [c[i] + = 2;    } return false;//does not establish}int main () {//Freopen ("In.txt", "R", stdin);    int kase = 0;    BOOL OK;        while (scanf ("%s", s) = = 1) {if (' 0 ' = = s[0]) break;        Id[0] = GetID (s);            for (int i = 1; i < ++i) {scanf ("%s", s);        Id[i] = GetID (s);//Get id//printf ("%d%d\n", I, id[i]);        }//printf ("\ n");        OK = false;        memset (c, 0, sizeof (c));//each time you want to empty for (int i = 0; i <; ++i) ++c[id[i]];//get the number of each card//puts ("+ +");        printf ("Case%d:", ++kase); for (int i = 0; i < ++i) {if (C[i] > 3) Continue;//If this card has four cards, you can no longer listen to, is the pit ++c[i];                if (judge ()) {OK = true;        printf ("%s", Mahjong[i]);//output}--c[i];        } if (!ok) printf ("Not Ready");    printf ("\ n"); } return 0;}

UVa 11210 Chinese Mahjong (violence, recursive search)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.