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 ...
随机推荐
- Leetcode-Best Time to Buy and Sell Stock -java
题目: Say you have an array for which the ith element is the price of a given stock on day i. If you w ...
- Redhat 6配置本地Yum源
注明:我的方法适用于iso镜像(光盘或光盘镜像:iso9660) 1.挂载(mount) 其它的mount方法可參见此链接 http://www.jb51.net/os/RedHat/1109.htm ...
- gcc 源代码下载地址
ftp://mirrors-usa.go-parts.com/gcc/releases/
- nj03---阻塞和线程
Node.js最大的特性就是"异步式I/O"与事件紧密结合的编程模式.这种模式与传统的同步式IO线性的编程思路有很大的不同,因为控制流很大程度上要靠"事件"和& ...
- zzulioj--1828-- 贪心的小猫咪(贪心模拟)
1828: 贪心的小猫咪 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 14 Solved: 4 SubmitStatusWeb Board Des ...
- POJ 3665 模拟
按照题意模拟就OK了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...
- jqueryValidator自定义校验规则的一种方式(不覆盖源码)
1.封装自定义验证方法-validate-methods.js /***************************************************************** j ...
- 监控rman备份
1.服务会话关联通道设置 set COMMAND ID 命令 2.查询V$PROCESS和V$SESSION 决定会话对应的RMAN的通道 3.查询V$session_LONGGOPS监控备份集和复制 ...
- ViewPager中的数据更新
getItemPosition(Object object) { return POSITION_NONE;} 出现的问题: 我希望能够通过调用 mAdapter.notifyDataSetChang ...
- FlatternMap和Map的区别
flattenMap使用步骤: 1.传入一个block,block类型是返回值RACStream,参数value 2.参数value就是源信号的内容,拿到源信号的内容做处理 3 ...