Uva China Mahjong (Chinese Mahjong,uva 11210)

Source: Internet
Author: User

A simple backtracking question

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7 Char*mahjong[]={8                                 "1T","2T","3T","4T","5T","6T","7T","8T","9T",9                                 "1S","2S","3S","4S","5S","6S","7S","8S","9S",Ten                                 "1W","2W","3W","4W","5W","6W","7W","8W","9W", One                                 " Dong","NAN","XI","BEI", A                                 "ZHONG","FA","BAI" -                                 }; -  the intConvertChar*s)//mapping processing - { -      for(intI=0;i< the; i++) -         if(strcmp (mahjong[i],s) = =0) +             returni; -     return-1; + } A  at intc[ the]; -  - BOOLSearchintDEP) - { -      for(intI=0;i< the; i++)//enumeration of the inscribed sub - -         if(c[i]>=3) in         { -             if(dep==3)return true; toc[i]-=3; +             if(Search (dep+1))return true; -c[i]+=3; the         } *      for(intI=0;i< the; i++)//Enumerate CIS $         if(i%9<=6&&c[i]>=1&&c[i+1]>=1&&c[i+2]>=1)Panax Notoginseng         { -             if(dep==3)return true; thec[i]--;c[i+1]--;c[i+2]--; +             if(Search (dep+1))return true; Ac[i]++;c[i+1]++;c[i+2]++; the         } +     return false; - } $  $ BOOLCheck () - { -      for(intI=0;i< the; i++)//Enumerate the cards the         if(c[i]>=2) -         {Wuyic[i]-=2; the             if(Search (0))return true; -c[i]+=2; Wu         } -     return false; About } $  - intMain () - { -     intcasen=0; A     intmj[ the]; +     Chars[ -]; the     BOOLOK; -      while(cin>>s) $     { the         if(s[0]=='0') Break; theprintf"Case %d:",++Casen); themj[0]=convert (s); the          for(intI=1;i< -; i++) -         { inCin>>s; themj[i]=convert (s); the         } Aboutok=false; the          for(intI=0;i< the; i++)//enumerate the draw the         { theMemset (c,0,sizeof(c)); +              for(intj=0;j< -; j + +) c[mj[j]]++; -             if(c[i]>=4)Continue; thec[i]++;Bayi             if(check ()) the             { theok=true; -printf"%s", Mahjong[i]); -             } thec[i]--; the         } the         if(!OK) theprintf" not ready"); -printf"\ n"); the     } the     return 0; the}

Uva China Mahjong (Chinese Mahjong,uva 11210)

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.