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 模拟的更多相关文章

  1. HDU 4431 Mahjong(模拟题)

    题目链接 写了俩小时+把....有一种情况写的时候漏了...代码还算清晰把,想了很久才开写的. #include <cstdio> #include <cstring> #in ...

  2. HDU - 4431 Mahjong (模拟+搜索+哈希+中途相遇)

    题目链接 基本思路:最理想的方法是预处理处所有胡牌的状态的哈希值,然后对于每组输入,枚举每种新加入的牌,然后用哈希检验是否满足胡牌的条件.然而不幸的是,由于胡牌的状态数过多(4个眼+一对将),预处理的 ...

  3. 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 ...

  4. HDU 4431 Mahjong (DFS,暴力枚举,剪枝)

    题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...

  5. Hdu 5379 Mahjong tree (dfs + 组合数)

    题目链接: Hdu 5379 Mahjong tree 题目描述: 给出一个有n个节点的树,以节点1为根节点.问在满足兄弟节点连续 以及 子树包含节点连续 的条件下,有多少种编号方案给树上的n个点编号 ...

  6. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  7. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

  8. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

  9. HDU 2568[前进]模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...

随机推荐

  1. poj3134 Power Calculus IDA*

    好端端的一道搜索题目,,,硬生生的被我弄成了乱搞题,,,枚举当前的maxd,深搜结果,然而想到的剪枝方法都没有太好的效果,,,最后用一个贪心乱搞弄出来了,,, 贪心:每次必用上一次做出来的数字与其他数 ...

  2. 建筑建模学习笔记2——3DMax房屋框架建模

    以下这幅图是用3DMax做出的大体的框架 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I ...

  3. 11.怎样自学Struts2之Struts2验证[视频]

    11.怎样自学Struts2之Struts2验证[视频] 之前写了一篇"打算做一个视频教程探讨怎样自学计算机相关的技术",优酷上传不了.仅仅好传到百度云上: http://pan. ...

  4. 4.bind绑定

    #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost ...

  5. 9-第一个app项目

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  6. [转]60fps on the mobile web

    Flipboard launched during the dawn of the smartphone and tablet as a mobile-first experience, allowi ...

  7. rails 开发随手记 7

    jQuery 1.9 中如何修改选择项 $("select option:contains(teacher5)").prop('selected', 'selected'); 效果 ...

  8. 使用HANDLECOLLISIONS的几个场景

    使用HANDLECOLLISIONS的几个场景: 1.target丢失delete记录(missing delete),忽略该问题并不记录到discardfile 2.target丢失update记录 ...

  9. pcre 不支持 utf 的问题

    问题: Error 500  preg_match(): Compilation failed: this version of PCRE is compiled without UTF suppor ...

  10. CSS 预处理语言之 less 篇

    less 前言 Less 是一门 CSS 预处理语言,它扩充了 CSS 语言,增加了诸如变量.混合(mixin).函数等功能,让 CSS 更易维护.方便制作主题.扩充. 安装 客户端使用 // 引入 ...