hdu4431 Mahjong
Mahjong
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2464 Accepted Submission(s): 522

One to nine Man, which we use 1m to 9m to represent;
One to nine Sou, which we use 1s to 9s to represent;
One to nine Pin, which we use 1p to 9p to represent;
Character tiles, which are:Ton, Nan, Sei, Pei, Haku, Hatsu, Chun, which we use 1c to 7c to represent.
A winning state means a set of 14 tiles that normally contains a pair of same tiles (which we call "eyes") and four melds. A meld is formed by either three same tiles(1m, 1m, 1m or 2c, 2c, 2c for example) or three continuous non-character tiles(1m, 2m, 3m or 5s, 6s, 7s for example).
However, there are two special winning states that are different with the description above, which are:
"Chii Toitsu", which means 7 different pairs of tiles;
"Kokushi Muso", which means a set of tiles that contains all these tiles: 1m, 9m, 1p, 9p, 1s, 9s and all 7 character tiles. And the rest tile should also be one of the 13 tiles above.
And the game starts with four players receiving 13 tiles. In each round every player must draw one tile from the deck one by one. If he reaches a winning state with these 14 tiles, he can say "Tsu Mo" and win the game. Otherwise he should discard one of his 14 tiles. And if the tile he throws out can form a winning state with the 13 tiles of any other player, the player can say "Ron" and win the game.
Now the question is, given the 13 tiles you have, does there exist any tiles that can form a winning state with your tiles?
(Notes: Some of the pictures and descriptions above come from Wikipedia.)
1s 2s 3s 2c 2c 2c 2p 3p 5m 6m 7m 1p 1p
1p 1p 2p 3p 4s 5s 6s 7c 7c 3s 3s 2m 2m
Nooten
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
char charmap[34][3]={
"1m","2m","3m","4m","5m","6m","7m","8m","9m",
"1s","2s","3s","4s","5s","6s","7s","8s","9s",
"1p","2p","3p","4p","5p","6p","7p","8p","9p",
"1c","2c","3c","4c","5c","6c","7c"};
int num19[15]={0,8,9,17,18,26,27,28,29,30,31,32,33},num[34];
int prime[34],result[40],ans,all=33;char str[13];
int charchange(char ss[])
{
switch(ss[1])
{
case 'm':return ss[0]-'0'-1;
case 's':return 8+ss[0]-'0';
case 'p':return 17+ss[0]-'0';
case 'c':return 26+ss[0]-'0';
}
return -1;
}
int find1()
{
int i,j,k,cnt;
for(i=0;i<=all;i++)
{
if(num[i]>=2)
{
cnt=0;
for(j=0;j<=all;j++)
{
if(i!=j)prime[j]=num[j];
else prime[j]=num[j]-2;
}
for(j=0;j<=all;j++)
{
if(prime[j]>=3)
{
prime[j]-=3;
cnt++;
}
if(prime[j]>0)
{
k=prime[j];
if(j+2<27&&prime[j+1]>=k&&prime[j+2]>=k&&j/9==(j+2)/9)
{
cnt+=k;
prime[j]-=k,prime[j+1]-=k,prime[j+2]-=k;
}
}
}
if(cnt==4)
return 1;
}
}
return 0;
}
int find2()
{
int i;
for(i=0;i<=all;i++)
{
if(num[i]!=2&&num[i]!=0)
return 0;
}
return 1;
}
int find3()
{
int i,r=0;
for(i=0;i<13;i++)
{
if(num[num19[i]]==0)
return 0;
r+=num[num19[i]];
}
if(r==14)
return 1;
return 0;
}
int main()
{
int n,i,k,j;
scanf("%d",&n);
while(n--)
{
ans=-1;
memset(num,0,sizeof(num));
for(i=0;i<13;i++)
{
scanf("%s",str);
num[charchange(str)]++;
}
//for(i=0;i<=all;i++)
//printf("i%d %d i\n",i,num[i]);
for(i=0;i<=all;i++)
{
if(num[i]>=4)
continue;
num[i]++;
if(find1())
result[++ans]=i;
else if(find2())
result[++ans]=i;
else if(find3())
result[++ans]=i;
num[i]--;
}
if(ans>=0)
{
printf("%d",ans+1);
for(i=0;i<=ans;i++)
{
printf(" %c%c",charmap[result[i]][0],charmap[result[i]][1]);
}
printf("\n");
}
else
printf("Nooten\n");
}
return 0;
}
hdu4431 Mahjong的更多相关文章
- hdu4431 Mahjong 枚举搜索。。
japanese麻将什么玩意..都没有豪华七对... 没什么难的 就是枚举搜索了 分三种类型的胡牌 f1是七对 f2是十三幺 f3是普通的胡牌 就先找一对 再找三个三个的 就是一直超时..在峰峰的指导 ...
- 2015暑假多校联合---Mahjong tree(树上DP 、深搜)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5379 Problem Description Little sun is an artis ...
- UVa 11210 (DFS) Chinese Mahjong
大白书第一章的例题,当时看起来很吃力,现如今A这道题的话怎么写都无所谓了. 思路很简单,就是枚举胡哪张牌,然后枚举一下将牌,剩下如果能找到4个顺子或者刻子就胡了. 由于粗心,34个字符串初始化写错,各 ...
- HDU 4431 Mahjong (DFS,暴力枚举,剪枝)
题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...
- uva 11210 Chinese Mahjong(暴力搜索)
Chinese Mahjong Mahjong () is a game of Chinese origin usually played by four persons with tiles res ...
- Chinese Mahjong UVA - 11210 (暴力+回溯递归)
思路:得到输入得到mj[]的各个牌的数量,还差最后一张牌.直接暴力枚举34张牌就可以了. 当假设得到最后一张牌,则得到了的牌看看是不是可以胡,如果可以胡的话,就假设正确.否者假设下一张牌. 关键还是如 ...
- Chinese Mahjong UVA - 11210 (DFS)
先记录下每一种麻将出现的次数,然后枚举每一种可能得到的麻将,对于这个新的麻将牌,去判断可不可能胡,如果可以胡,就可以把这张牌输出出来. 因为eye只能有一张,所以这个是最好枚举的,就枚举每张牌成为ey ...
- UVa 11210 Chinese Mahjong (暴力,递归寻找)
题意:这个题意.有点麻烦,就是说给定13张牌,让你求能“听”的牌.(具体的见原题) 原题链接: https://uva.onlinejudge.org/index.php?option=com_onl ...
- bzoj 1860: [Zjoi2006]Mahjong麻将 题解
[原题] 1860: [Zjoi2006]Mahjong麻将 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 211 Solved: 122 [Subm ...
随机推荐
- python 模块BeautifulSoup使用
BeautifulSoup是一个专门用于解析html/xml的库.官网:http://www.crummy.com/software/BeautifulSoup/ 说明,BS有了4.x的版本了.官方说 ...
- Windbg调试命令详解(2)
转载注明>> [作者:张佩][原文:http://blog.csdn.net/blog_index] 2. 符号与源码 符号与源码是调试过程中的重要因素,它们使得枯燥生硬的调试内容更容易 ...
- iOS开发 日常错误积累
1.ios7 tableviewcell上面加入一个view,view上面有button,点击button不运行button的点击事件 解决的方法: self.view.userInteraction ...
- IIS7.0+SqlServer2012,进行.net网站发布的安装全过程
1..net3.5安装(sqlserver2012需要) 控制面板-->管理工具-->服务器管理器-->功能-->添加功能-->选择".NET Framewor ...
- 【Hibernate】Illegal attempt to associate a collection with two open sessions
今天在用Hibernate对对象进行修改操作的时候报了这个错. 之前一直没什么错误,但是今天修改了一下表结构,增加了一个OneToMany的映射. 所以在我获取对象,重新set一个变量之后就报了这个错 ...
- 自定义ActionBar背景(分别针对3.0以下和3.0以上的版本)
官方原文:http://developer.android.com/training/basics/actionbar/styling.html 针对3.0以上的版本: <?xml versio ...
- Markdown 11 种基础语法
现在是我在学习Markdown时做的笔记.学完这些Markdown的基本使用已经不成问题. 1. 标题设置(让字体变大,和word的标题意思一样)在Markdown当中设置标题,有两种方式: 第一种: ...
- Python 2.7 学习笔记 面向对象的编程
python是一种面向对象的语言.本文介绍如何用python进行面向对象的编程. 首先我们说下对象和类,类是一种类型的定义,对象是类的实例. 一.内置对象类型(内置类) 其实我们前面已经大量用到了对象 ...
- Gradle构建Java Web应用:Servlet依赖与Tomcat插件(转)
Gradle的官方tutorial介绍了构建Java Web应用的基本方法.不过在使用Servlet做上传的时候会碰到问题.这里分享下如何通过Servlet上传文件,以及如何使用Gradle来构建相应 ...
- javascript语言精粹:继承
继承提供了2个有用的任务: 1.代码重用 2.引入了一套类型系统的规范,因为程序员无需编写显示类型转换的代码,他们的工作量将大大减轻.这是一件很好的事情,应为类型转换会丧失类型系统在安全上的优势. 在 ...