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

因为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. react render

    实际上react render方法返回一个虚拟dom 并没有去执行渲染dom 渲染的过程是交给react 去完成的 这就说明了为什么要在所有数据请求完成后才去实现render 这样做也提高了性能.只调 ...

  2. java Date时间的各种转换方式和Mysql存时间类型字段的分析

    一:各种Date之间的转换方法 public class TimeTest { public static void main(String[] args) { Date date = new Dat ...

  3. PHPWord插件详解

    一下载PHPWorld并配置项目 1.PHPWord框架文件如下: 二使用word模板并使用PHPWord生成doc文件 例如:源代码如下: <?php require_once '../PHP ...

  4. SLAs-笔记

    类型 sla status determined at time intervals over a timeline: average transaction response time errors ...

  5. Jackson将对象转换为json字符串时,设置默认的时间格式

    maven需要的依赖: <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifac ...

  6. Bootstrap之登陆页面范例

    代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta ...

  7. indexOf刚开始写成IndexOf出错

    {{# if(d.fronturlmin ==null||d.fronturlmin ==""){ }} <img src="@System.Configurati ...

  8. 小米Note3 MIUI9可以用的XPosed框架

    资源来自论坛里的:http://www.miui.com/thread-6449305-1-1.html 首先需要刷入TWRP,资源在这个帖子里:http://www.miui.com/thread- ...

  9. 启用chacha20和salsa20等加密方法

    wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz tar zxf LATEST.tar.gz cd libsod ...

  10. React Router 4.0 基本使用

    路由的概念,起初来源于服务端,就是当浏览器访问一个网站的不同页面时,服务端能够正确的返回页面的内容.当访问首页时,它能返回首页的内容,访问关于我们页面时,返回关于我们的内容.可以看到路由就是一种控制和 ...