Ultraviolet A 11210 Chinese Mahjong (Chinese mahjong, big simulation)

Source: Internet
Author: User

Solution:

The key lies in how to determine whether the fourteen cards can match the cards. Here we use DFS to determine whether the cards can match the cards. For details, see the code.

# Include <iostream> # include <cstring> # include <cstdlib> # include <cstdio> # include <algorithm> # include <vector> # include <queue> # include <set> # include <map> # include <stack> using namespace STD; const int maxn = 1000 + 10; string card [] = {"1 t", "2 t", "3 T", "4 T", "5 t ", "6 T", "7 t", "8 t", "9 t", "1 s", "2 s", "3 S", "4 s ", "5 s", "6 s", "7 s", "8 s", "9 s", "1 W", "2 W", "3 W ", "4 W", "5 W", "6 W "," 7 W "," 8 W "," 9 W "," Dong "," Nan "," Xi "," Bei "," Zhong "," Fa ", "bai"}; string s [20]; int C [maxn]; int H [maxn]; int ID (string s) {for (INT I = 0; I <34; I ++) if (S = card [I]) return I; Return-1;} int DFS (INT dep) {for (INT I = 0; I <34; I ++) if (H [I]> = 3) {If (DEP = 3) return 1; H [I]-= 3; if (DFS (DEP + 1) return 1; H [I] + = 3 ;}for (INT I = 0; I <= 24; I ++) if (I % 9 <= 6 & H [I]> = 1 & H [I + 1]> = 1 & H [I + 2]> = 1) {If (DEP = 3) return 1; H [I] --; H [I + 1] --; H [I + 2] --; If (DFS (DEP + 1) return 1; H [I] ++; H [I + 1] ++; H [I + 2] ++;} return 0;} bool check () {for (INT I = 0; I <34; I ++) {If (H [I]> = 2) {H [I]-= 2; if (DFS (0) return 1; H [I] + = 2 ;}} return 0 ;}int solve () {int flag = 0; for (INT I = 0; I <34; I ++) {memset (H, 0, sizeof (h); For (Int J = 0; j <13; j ++) H [C [J] ++; If (H [I]> = 4) continue; H [I] ++; If (check ()) {flag = 1; cout <''<card [I];} H [I] --;} If (! Flag) printf ("not ready"); printf ("\ n") ;}int main () {string STR; int kcase = 1; while (CIN> STR & Str! = "0") {s [0] = STR; C [0] = ID (STR); For (INT I = 1; I <13; I ++) {CIN> S [I]; C [I] = ID (s [I]);} printf ("case % d:", kcase ++ ); solve ();} return 0 ;}

Ultraviolet A 11210 Chinese Mahjong (Chinese mahjong, big simulation)

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.