Chinese Mahjong UVA - 11210 (DFS)
先记录下每一种麻将出现的次数,然后枚举每一种可能得到的麻将,对于这个新的麻将牌,去判断可不可能胡,如果可以胡,就可以把这张牌输出出来。
因为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)的更多相关文章
- Chinese Mahjong UVA - 11210 (暴力+回溯递归)
思路:得到输入得到mj[]的各个牌的数量,还差最后一张牌.直接暴力枚举34张牌就可以了. 当假设得到最后一张牌,则得到了的牌看看是不是可以胡,如果可以胡的话,就假设正确.否者假设下一张牌. 关键还是如 ...
- UVa中国麻将(Chinese Mahjong,Uva 11210)
简单的回溯题 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm ...
- uva 211(dfs)
211 - The Domino Effect Time limit: 3.000 seconds A standard set of Double Six dominoes contains 28 ...
- UVA 1640(DFS)
题意:给你a,b两个数 问你a b区间中0 9出现的次数 其实就是求1-n中0-9出现的次数 ans[n] 答案就是ans[b]-ans[a-1] 怎么求的话看代码吧 #include<io ...
- LeetCode Subsets II (DFS)
题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...
- LeetCode Subsets (DFS)
题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...
- HDU 2553 N皇后问题(dfs)
N皇后问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 在 ...
- 深搜(DFS)广搜(BFS)详解
图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...
- 【算法导论】图的深度优先搜索遍历(DFS)
关于图的存储在上一篇文章中已经讲述,在这里不在赘述.下面我们介绍图的深度优先搜索遍历(DFS). 深度优先搜索遍历实在访问了顶点vi后,访问vi的一个邻接点vj:访问vj之后,又访问vj的一个邻接点, ...
随机推荐
- PHP导出CSV文件出现乱码的解决方法
在做项目时碰到使用外语的情况下,我们就会使用UTF-8编码.但是,在用PHP导出CSV文件时,如果写入的数据是使用UTF-8编码的日语.韩语之类的外文,就会出现乱码. 要解决PHP生成CSV文件的乱码 ...
- vsconsole
一.安装 npm install vconsole 二. if (process.env.NODE_ENV === `development`) { const { logger } = requir ...
- 关于JS动画和CSS3动画的性能差异
本文章为综合其它资料所得. 根据Google Developer,Chromium项目里,渲染线程分为main thread和compositor thread. 如果CSS动画只是改变transfo ...
- java不同的包下相同的类名的问题与解决办法
Java中的类以包进行分类组织,当程序中需要用到某个包下的类时,可以以该类的全限定名进行引用.这样,不同的包中的类就可以同名,不会产生混淆. 但是这样就可能导致引用的时候会产生一些问题. 第一个问题, ...
- Jenkins配置权限管理
借鉴博客:https://www.cnblogs.com/Eivll0m/p/6734076.html 懒得写了,照上面是配置成功了,弄了权限角色与用户的配置
- js获取数组中相同元素数量
<script> var array = new Array(1,2,5,1,4,4,2,3,5,1,1,5,5,5,6,7,3,9,9,10); var arr = new Array( ...
- C# Note24: 指针的使用
C#为了类型安全,默认并不支持指针.但是也并不是说C#不支持指针,我们可以使用unsafe关键词,开启不安全代码(unsafe code)开发模式.在不安全模式下,我们可以直接操作内存,这样就可以使用 ...
- MyBatis映射文件5
返回map Map<String,Object> getEmpByResMap(Integer id); <select id="getEmpByResMap&qu ...
- MySQL索引管理及执行计划
一.索引介绍 二.explain详解 三.建立索引的原则(规范)
- Leetcode SingleNumber I & II & III 136/137/260
SingleNumber I: 题目链接:https://leetcode-cn.com/problems/single-number/ 题意: 给定一个非空整数数组,除了某个元素只出现一次以外,其余 ...