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)