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. enterprise architect (EA) 源码生成UML类图,帮助理解项目工程

    用VS看大型工程代码,尤其是很多层类的,很容易头晕,即便是装了visual assist 插件.用VS生成类图吧,只能生成一堆框,只有一些小的类关系有箭头表示.远远不能满足要求.下面介绍建模工具EA来 ...

  2. BZOJ 2683 简单题 cdq分治+树状数组

    题意:链接 **方法:**cdq分治+树状数组 解析: 首先对于这道题,看了范围之后.二维的数据结构是显然不能过的.于是我们可能会考虑把一维排序之后还有一位上数据结构什么的,然而cdq分治却可以非常好 ...

  3. rest_framework 节流功能(访问频率)

    访问记录 = { 身份证号: [ :: ,::, ::] } #:: ,::,:: ,::, #:: #[::, ::, ::] #访问记录 = { 用户IP: [...] } import time ...

  4. 关于fetch

    前言: fetch是用来取代传统的XMLHttpRequest的. 它的优点很多,包括链式调用的语法.返回promise等. 什么是fetch? fetch api是基于promise的设计,它是为了 ...

  5. C#篇(二)——属性的实质

    属性的内部实现其实就是方法 我们平时写的代码: class Student { private int age; public int Age { get { return age; } set { ...

  6. SharePoint 修改完或制作完一定要发布

    设置了匿名访问但是网站就是需要登录,找了很多问题. 首先想到的映射问题,然后努力检查,最后把代码删掉,然后把站删掉,最后测试出来问题. 点击上方[网站设置] 把修改过的文件发布. 母版也和布局页 一定 ...

  7. 关于iOS适配问题

    大家都知道在iOS开发当中对于UI适配问题可以从如下两个方面去考虑: 1.比例适配 2.利用autolayout自动布局 通常情况来说,利用auto自动布局是一个比较好的方案,开发者可以利用story ...

  8. js确认框confirm()用法实例详解

    先为大家介绍javascript确认框的三种使用方法,具体内容如下 第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认. ? 1 2 3 4 5 6 7 8 ...

  9. HDU 2515 Yanghee 的算术【找规律】

    题意:中文的题目 找规律可以发现 sum[1]=a[1]+a[2] sum[2]=a[1]+a[3] sum[n]=a[2]+a[3] 解出a[1],就可以求出其他的了 #include<ios ...

  10. Java获取电脑硬件信息

    package com.szht.gpy.util; import java.applet.Applet; import java.awt.Graphics; import java.io.Buffe ...