HDU 4431 Mahjong 模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4431
不能说是水题了,具体实现还是很恶心的...几乎优化到哭但是DFS(还加了几个剪枝)还是不行...搜索一直T到死...贪心构造解就行算是长见识了
首先还是要枚举所有34张牌...然后再枚举将牌(2个的)...之后就是判断这副牌有没有胡牌了...肯定是要特判国士无双和七对的...再就是平胡的情况
平胡只要对每张牌优先刻子,再直接贪心向下构造顺子就行了......
/********************* Template ***********************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define EPS 1e-8
#define DINF 1e15
#define MAXN 100050
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 1LL<<60
#define PI 3.14159265358979323846
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define BUG cout<<"BUG! "<<endl
#define ABS(a) ((a)>0?(a):(-a))
#define LINE cout<<"------------------ "<<endl
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("out.txt","w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,b) for(int i = a ; i < b ; i++)
#define read(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define write(a) printf("%d\n",a)
#define write2(a,b) printf("%d %d\n",a,b)
#define write3(a,b,c) printf("%d %d %d\n",a,b,c)
#pragma comment (linker,"/STACK:102400000,102400000")
template<class T> inline T L(T a) {return (a << );}
template<class T> inline T R(T a) {return (a << | );}
template<class T> inline T lowbit(T a) {return (a & -a);}
template<class T> inline T Mid(T a,T b) {return ((a + b) >> );}
template<class T> inline T gcd(T a,T b) {return b ? gcd(b,a%b) : a;}
template<class T> inline T lcm(T a,T b) {return a / gcd(a,b) * b;}
template<class T> inline T Min(T a,T b) {return a < b ? a : b;}
template<class T> inline T Max(T a,T b) {return a > b ? a : b;}
template<class T> inline T Min(T a,T b,T c) {return min(min(a,b),c);}
template<class T> inline T Max(T a,T b,T c) {return max(max(a,b),c);}
template<class T> inline T Min(T a,T b,T c,T d) {return min(min(a,b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d) {return max(max(a,b),max(c,d));}
template<class T> inline T mod(T x,T y) {y = ABS(y); return x >= ? x % y : x % y + y;}
template<class T> inline T mul_mod(T a,T b,T n) {
T ret = ,tmp = a % n;
while(b){
if((b&) && (ret+=tmp)>=n) ret -= n;
if((b>>=) && (tmp<<=)>=n) tmp -= n;
}return ret;
}
template<class T> inline T pow_mod(T a,T b,T n){
T ret = ; a = a % n;
while(b){
if (b&) ret = mul_mod(ret,a,n);
if (b>>=) a = mul_mod(a,a,n);
}return ret;
}
template<class T> inline T exGCD(T a, T b, T &x, T &y){
if(!b) return x = ,y = ,a;
T res = exGCD(b,a%b,x,y),tmp = x;
x = y,y = tmp - (a / b) * y;
return res;
}
template<class T> inline T reverse_bits(T x){
x = (x >> & 0x55555555) | ((x << ) & 0xaaaaaaaa); x = ((x >> ) & 0x33333333) | ((x << ) & 0xcccccccc);
x = (x >> & 0x0f0f0f0f) | ((x << ) & 0xf0f0f0f0); x = ((x >> ) & 0x00ff00ff) | ((x << ) & 0xff00ff00);
x = (x >> & 0x0000ffff) | ((x <<) & 0xffff0000); return x;
}
typedef long long LL; typedef unsigned long long ULL;
typedef __int64 LL; typedef unsigned __int64 ULL;
/******************** By F ********************/
int ma[][],yy[],xx[];
//bool dfs(int c){
// if(c == 12) return true;
// for(int i = 0 ; i < 4 ; i++){
// for(int j = 1 ; j <= (i==3?7:9) ; j++){
// if(i != 3 && j <= 7 && ma[i][j] >= 1 && ma[i][j+1] >= 1 && ma[i][j+2] >= 1){
// ma[i][j] -= 1; ma[i][j+1] -= 1; ma[i][j+2] -= 1;
// if(dfs(c+3)) {
// ma[i][j] += 1; ma[i][j+1] += 1; ma[i][j+2] += 1;
// return true;
// }
// ma[i][j] += 1; ma[i][j+1] += 1; ma[i][j+2] += 1;
// }
// if(ma[i][j] >= 3){
// ma[i][j] -= 3;
// if(dfs(c+3)) {
// ma[i][j] += 3;
// return true;
// }
// ma[i][j] += 3;
// }
// }
// }
// return false;
//}
bool dfs(){
int ct = ;
int tmp[][];
for(int i = ; i < ; i++)
for(int j = ; j <= ; j++)
tmp[i][j] = ma[i][j];
for(int i = ; i < ; i++){
for(int j = ; j <= ; j++){
if(tmp[i][j] >= ){
tmp[i][j] -= ;
ct++;
}
while(j+ <= && tmp[i][j] >= && tmp[i][j+] >= && tmp[i][j+] >= ){
tmp[i][j]-=;
tmp[i][j+]-=;
tmp[i][j+]-=;
ct++;
}
}
}
for(int i = ; i <= ; i++)
if(tmp[][i] >= ) ct++;
if(ct == ) return true;
else return false;
}
bool judgeGuo(){
int ct1 = ,ct2 = ;
for(int i = ; i < ; i++){
if(ma[i][] == ) ct1++;
if(ma[i][] == ) ct2++;
if(ma[i][] == ) ct1++;
if(ma[i][] == ) ct2++;
if(ct2 > ) return false;
}
for(int i = ; i <= ; i++){
if(ma[][i] == ) ct1++;
if(ma[][i] == ) ct2++;
if(ct2 > ) return false;
}
if(ct1 == && ct2 == ) return true;
return false;
}
bool judge7dui(){
int cnt = ;
for(int i = ; i < ; i++){
for(int j = ; j <= (i==?:) ; j++){
if(ma[i][j] != && ma[i][j] != ) return false;
if(ma[i][j] == ) cnt++;
}
}
if(cnt == ) return true;
return false;
}
bool judge(){
if(judgeGuo()) return true;
if(judge7dui()) return true;
for(int i = ; i < ; i++){
for(int j = ; j <= (i==?:) ; j++){
if(ma[i][j] >= ){
ma[i][j] -= ;
if(dfs()) {
ma[i][j] += ;
return true;
}
ma[i][j] += ;
}
}
}
return false;
}
int main(){
//FIN;
//FOUT;
int T;
char t[];
scanf("%d",&T);
int i,j;
while(T--){
mem(ma,);
for(i = ; i < ; i++){
scanf("%s",t);
if(t[] == 'm') ma[][t[]-'']++;
else if(t[] == 's') ma[][t[]-'']++;
else if(t[] == 'p') ma[][t[]-'']++;
else if(t[] == 'c') ma[][t[]-'']++;
}
int cnt = ;
for(i = ; i < ; i++){
for(j = ; j <= (i==?:) ; j++){
if(ma[i][j] < (i==?:) ){
ma[i][j]++;
if(judge()) {
xx[cnt] = i;
yy[cnt++] = j;
}
ma[i][j]--;
}
}
}
if(cnt == ){
printf("Nooten\n");
continue;
}else{
printf("%d",cnt);
for(i = ; i < cnt ; i++){
if(xx[i] == ) printf(" %dm",yy[i]);
else if(xx[i] == ) printf(" %ds",yy[i]);
else if(xx[i] == ) printf(" %dp",yy[i]);
else if(xx[i] == ) printf(" %dc",yy[i]);
}
putchar('\n');
}
}
return ;
}
HDU 4431 Mahjong 模拟的更多相关文章
- HDU 4431 Mahjong(模拟题)
		题目链接 写了俩小时+把....有一种情况写的时候漏了...代码还算清晰把,想了很久才开写的. #include <cstdio> #include <cstring> #in ... 
- HDU - 4431 Mahjong (模拟+搜索+哈希+中途相遇)
		题目链接 基本思路:最理想的方法是预处理处所有胡牌的状态的哈希值,然后对于每组输入,枚举每种新加入的牌,然后用哈希检验是否满足胡牌的条件.然而不幸的是,由于胡牌的状态数过多(4个眼+一对将),预处理的 ... 
- HDU 4431 Mahjong(枚举+模拟)(2012 Asia Tianjin Regional Contest)
		Problem Description Japanese Mahjong is a four-player game. The game needs four people to sit around ... 
- HDU 4431 Mahjong (DFS,暴力枚举,剪枝)
		题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ... 
- Hdu 5379 Mahjong tree (dfs + 组合数)
		题目链接: Hdu 5379 Mahjong tree 题目描述: 给出一个有n个节点的树,以节点1为根节点.问在满足兄弟节点连续 以及 子树包含节点连续 的条件下,有多少种编号方案给树上的n个点编号 ... 
- HDU 4121 Xiangqi 模拟题
		Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ... 
- hdu 5071 Chat(模拟)
		题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ... 
- hdu 4740【模拟+深搜】.cpp
		题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ... 
- HDU 2568[前进]模拟
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ... 
随机推荐
- Java的TreeMap,C++的lower_bound,合并间隔
			https://leetcode.com/problems/data-stream-as-disjoint-intervals/?tab=Description 这道题目是合并间隔的经典题目. htt ... 
- Android与设计模式——单例(Singleton)模式
			概念: java中单例模式是一种常见的设计模式.单例模式分三种:懒汉式单例.饿汉式单例.登记式单例三种. 单例模式有一下特点: 1.单例类仅仅能有一个实例. 2.单例类必须自己自己创建自己的唯一实例. ... 
- 【POJ 1845】 Sumdiv (整数唯分+约数和公式+二分等比数列前n项和+同余)
			[POJ 1845] Sumdiv 用的东西挺全 最主要通过这个题学了约数和公式跟二分求等比数列前n项和 另一种小优化的整数拆分 整数的唯一分解定理: 随意正整数都有且仅仅有一种方式写出其素因子的乘 ... 
- POJ 3277 线段树+扫描线
			题意: 思路: 线段树求矩形面积的并...同 POJ 1151 //By SiriusRen #include <cstdio> #include <algorithm> us ... 
- 加载等待loading
			自己写的一个小插件,还有很多需要完善... (function ($) { $.fn.StartLoading = function (option) { var defaultV ... 
- EasyUI 之 DataGrid利用用拉姆达表达式实现分页查询
			首先,我们在DataGrid的URL中加上我们要查询的条件:查询用户名不是“呵呵”的所有用户. <div> <table id="dg" class=&quo ... 
- JS中的switch case
			function GetDepartmentName(type) { switch (type) { case DepartMentQian: alert($('#DepartMentQian').v ... 
- python中修改函数内部的变量会发生什么
			最近写python遇到个函数内部变量使用外部变量的问题,现在总结下吧 #!/usr/bin/env python a = 100def su(): a = a + 1 print(a) s = su( ... 
- UI Framework-1: Aura Focus and Activation
			Focus and Activation Focus and Activation are closely related. Definitions Focused window - this i ... 
- DedeCMS文章编辑不更新时间1970年1月1日
			在修改文章或者后期优化的时候,织梦dedecms5.7版本存在一个问题,修改文章的同时也修改了文章的发布时间,这个功能可能有些人比较需要,但同时也有些站长朋友又不需要,因为我们编辑某个文章的时候,发现 ... 
