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的一个邻接点, ...
随机推荐
- selenium处理alert弹出框
import time from selenium import webdriver driver =webdriver.Chrome(r"D:\工具包\chromedriver.exe&q ...
- yum 命令
yum( Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器. 基於RPM包管理,能够从指定的服务器自动下载RPM包 ...
- 使用jmeter来发送json/gzip格式数据 --------笔记
一.使用jmeter来发送gzip数据 有时候我们需要模拟在客户端将数据压缩后, 发送(post)到服务器端. 通常这种情况,会发生在移动终端上. 这样做的好处, 是可以节省流量. 当然, 服务器返 ...
- Cookie-parser
let express = require('express'); let app =new express(); // 引入cookie-parser; let cookieParser = req ...
- GANs (Generative Adversarial Networks)
#!/usr/bin/python2.7 #coding:utf-8 import tensorflow as tf import numpy as np import matplotlib.pypl ...
- Keras和tensorflow的区别
参考: https://blog.csdn.net/zhangbaoanhadoop/article/details/82111056
- Golang的方法传递值应该注意的地方
其实最近看了不少Golang接口以及方法的阐述都有一个地方没说得特别明白.就是在Golang编译隐式转换传递给方法使用的时候,和调用函数时的区别. 我们都知道,在我们为一个类型变量申明了一个方法的时候 ...
- Prism框架研究(一)
从今天起开始写一个Prism框架的学习博客,今天是第一篇,所以从最基本的一些概念开始学习这个基于MVVM的框架的学习,首先看一下Prism代表什么,这里引用一下比较官方的英文解释来看一下:Prism ...
- github & markdown & collapse & table
github & markdown collapse & table https://github.com/Microsoft/TypeScript/issues/30034 GitH ...
- ajax查看详细返回信息
查看详细成功返回信息: success : function(data, textStatus, jqXHR) { console.log(data); console.log(textStatus) ...