先记录下每一种麻将出现的次数,然后枚举每一种可能得到的麻将,对于这个新的麻将牌,去判断可不可能胡,如果可以胡,就可以把这张牌输出出来。

因为eye只能有一张,所以这个是最好枚举的,就枚举每张牌成为eye的可能,然后对于剩下的牌去判断成为pong和chow的可能,然后判断可不可能胡牌

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x))
#define INOPEM freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 2e6+;
const int maxm = ;
const int mod = 1e9+;
using namespace std; int n, m;
int T, tol;
char *Mahjong[] = {
"", "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 cnt[];
int id[]; void init() {
memset(cnt, , sizeof cnt);
} int find(char *s) {
for(int i=; i<; i++)
if(strcmp(s, Mahjong[i]) == )
return i;
} bool dfs(int count) {
if(count == ) return true;
for(int i=; i<=; i++) {
if(cnt[i] >= ) {
cnt[i] -= ;
if(dfs(count+)) return true;
cnt[i] += ;
}
}
for(int i=; i<=; i++) {
if(cnt[i] >= && cnt[i+] >= && cnt[i+] >= ) {
cnt[i] -= , cnt[i+] -= , cnt[i+] -= ;
if(dfs(count+)) return true;
cnt[i] += , cnt[i+] += , cnt[i+] += ;
}
}
return false;
} bool judge() {
for(int i=; i<=; i++) {
if(cnt[i] >= ) {
cnt[i] -= ;
if(dfs()) return true;
cnt[i] += ;
}
}
return false;
} int main() {
char tmp[];
int cas = ;
while(scanf("%s", tmp)) {
if(tmp[] == '') break;
init();
id[] = find(tmp);
for(int i=; i<=; i++) {
scanf("%s", tmp);
id[i] = find(tmp);
}
printf("Case %d:", cas++);
bool flag = false;
for(int i=; i<=; i++) {
if(Mahjong[i][] == '') continue;
memset(cnt, , sizeof cnt);
for(int j=; j<=; j++) cnt[id[j]]++;
if(cnt[i] >= ) continue;
cnt[i]++;
if(judge()) {
flag = true;
printf(" %s", Mahjong[i]);
}
}
if(!flag) printf(" Not ready");
printf("\n");
}
return ;
}

Chinese Mahjong UVA - 11210 (DFS)的更多相关文章

  1. Chinese Mahjong UVA - 11210 (暴力+回溯递归)

    思路:得到输入得到mj[]的各个牌的数量,还差最后一张牌.直接暴力枚举34张牌就可以了. 当假设得到最后一张牌,则得到了的牌看看是不是可以胡,如果可以胡的话,就假设正确.否者假设下一张牌. 关键还是如 ...

  2. UVa中国麻将(Chinese Mahjong,Uva 11210)

    简单的回溯题 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm ...

  3. uva 211(dfs)

    211 - The Domino Effect Time limit: 3.000 seconds A standard set of Double Six dominoes contains 28 ...

  4. UVA 1640(DFS)

    题意:给你a,b两个数 问你a b区间中0 9出现的次数 其实就是求1-n中0-9出现的次数 ans[n]   答案就是ans[b]-ans[a-1] 怎么求的话看代码吧 #include<io ...

  5. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  6. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  7. HDU 2553 N皇后问题(dfs)

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在 ...

  8. 深搜(DFS)广搜(BFS)详解

    图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...

  9. 【算法导论】图的深度优先搜索遍历(DFS)

    关于图的存储在上一篇文章中已经讲述,在这里不在赘述.下面我们介绍图的深度优先搜索遍历(DFS). 深度优先搜索遍历实在访问了顶点vi后,访问vi的一个邻接点vj:访问vj之后,又访问vj的一个邻接点, ...

随机推荐

  1. windows下linux子系统安装

    1.打开Windows功能中的使用于linux的Windows子系统 2.应用商店中下载需要的linux 3.下载完成后运行等待安装并输入用户名密码  4.查看系统信息 先后 sudo apt-get ...

  2. PHP的优化建议(仅借鉴)

    转载: https://www.awaimai.com/1050.html 1 字符串 1.1 少用正则表达式 能用PHP内部字符串操作函数的情况下,尽量用他们,不要用正则表达式, 因为其效率高于正则 ...

  3. [转帖]linux下的X server:linux图形界面原理

    linux下的X server:linux图形界面原理 https://www.cnblogs.com/liangxiaofeng/p/5034912.html linux下的X server:lin ...

  4. [转帖]前端-chromeF12 谷歌开发者工具详解 Sources篇

    前端-chromeF12 谷歌开发者工具详解 Sources篇 原贴地址:https://blog.csdn.net/qq_39892932/article/details/82498748 cons ...

  5. [学习]UX 测试 5S 范围

    最近被UX测试搞的死去活来的 郁闷坏了. 豆瓣上面有一个介绍: 好的框架总是简洁的. Strategy - Scope - Structure - Skeleton - Surface五个层面,用bo ...

  6. python之路--装饰器

    二 .通用装饰器的写法 python里面的动态代理. 存在的意义: 在不破坏原有的函数和原有函数的调用基础上,给函数添加新的功能 def wrapper(fn): # fn是目标函数. def inn ...

  7. python数学第二天【泰勒展开式】

    1. 泰勒展开式 推论1: 泰勒展开式的应用 推论2: 推论3:

  8. swagger bug

    https://blog.csdn.net/u011943534/article/details/81778125 处理swagger报错Could not resolve pointer: /def ...

  9. CSS 常见的8种选择器 和 文本溢出问题

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>c ...

  10. debug方法

    debug as -> spring boot->开始了 可以添加 ,, 来进行向下步骤:使用其他方法(在方法内打点) 一步步F6就可以了