Mahjong

原创 2015年11月19日 21:44:58

Mahjong is a favorite pastime in China. It can be played either with a set of mahjong tiles or a set of mahjong playing cards (sometimes spelled "kards" to distinguish them from the list of standard hands used in American mahjong). One brand of mahjong cards calls these Mhing. Playing cards are often used when travelling, as they take up less space and are lighter than their tile counterparts;however, they are usually of a lower quality. In this article, "tile" will be used to denote both playing cards and tiles.

There are many variations of mahjong. In many places, players often observe one version and are either unaware of other variations or claim that different versions are incorrect. Here, we are using the 13-tile version.

In order to simplify the problem. We only consider 13 tiles of Suit Character (named as each tile represents ten thousand coins, or one hundred strings of one hundred coins):

We use a single integer (1 to 9) to represent a tile (Character 1 to 9) in this problem.

In this simplified problem, consider below melds only(refer to Mahjong - Wikipedia for complete description):

  • Pong, or Pung, is a set of three identical tiles.
    For example: 9 9 9; 7 7 7;
  • Chow is a meld of three suited tiles in sequence.
    For example: 1 2 3; 3 4 5; 7 8 9; 5 6 7;
  • An Eye is the pair, while not a meld (and thus cannot be declared or formed with a discard, except if completing the pair completes the hand), is the final component to the standard hand. It consists of any two identical tiles.
    For example: 1 1; 7 7;

A player wins by creating a standard mahjong hand, which consists of a certain number of melds (four for 13-tile version) and a single Eye.

Your task is to figure out which tile can make you win according to 13 tiles you already have.

Note that you can't have more than 4 tiles with a same number at any time.

Input

Multi cases (no more than 25). Process to the end.

Each case has a single line containing 13 integers, which are tiles you already have.

Output

For each case, output tiles that can make you win in one line(sorted, smaller first), separated by one space. There is always a solution.

Sample Input

1 3 4 4 4 4 5 6 6 7 7 7 8

Sample Output

2


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int a[10],flag;

void dfs(int x,int y)
{
	if(y>1||flag) return;
	if(x==4&&y==1) {
		flag=1;
		return;
	}
	for(int i=1;i<=9;i++) {
		if(a[i]>=2) {
			a[i]-=2;
			dfs(x,y+1);
			a[i]+=2;
		}
		if(a[i]>=3) {
			a[i]-=3;
			dfs(x+1,y);
			a[i]+=3;
		}
		if(i+2<=9&&a[i]>=1&&a[i+1]>=1&&a[i+2]>=1) {
			a[i]-=1; a[i+1]-=1; a[i+2]-=1;
			dfs(x+1,y);
			a[i]+=1; a[i+1]+=1; a[i+2]+=1;
		}
	}
}

int main()
{
	int t;
	while(scanf("%d",&t)!=EOF)
	{
		int i,first=1;
		memset(a,0,sizeof(a));
		a[t]++;
		for(i=0;i<12;i++) scanf("%d",&t),a[t]++;
		for(i=1;i<=9;i++) if(a[i]<4) {
			flag=0;
			a[i]++;
			dfs(0,0);
			if(flag) {
				if(first) first=0;
				else printf(" ");
				printf("%d",i);
			}
			a[i]--;
		}
		printf("\n");
	}
	return 0;
}
心得:深搜时,要注意恢复先前改变的变量。

深搜最好不要返回bool类型

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 4431 Mahjong (麻将、神坑模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4431 题面: Mahjong Time Limit: 4000/2000 MS (J...
  • David_Jett
  • David_Jett
  • 2015年07月27日 18:32
  • 1425

hdu4431 Mahjong 枚举搜索。。

japanese麻将什么玩意。。都没有豪华七对。。。 没什么难的 就是枚举搜索了 分三种类型的胡牌 f1是七对 f2是十三幺 f3是普通的胡牌 就先找一对 再找三个三个的 就是一直超时。。在峰峰的指导...
  • u011032846
  • u011032846
  • 2013年08月20日 14:47
  • 1010

中国麻将(Chinese Mahjong, UVa 11210)【JAVA算法实现】

题目描述 麻将是一个中国原创的4人玩的游戏。这个游戏有很多变种,但本题只考虑一种有136张牌的玩法。这136张牌所包含的内容如下。 饼(筒)牌:每张牌包括一系列点,每个点代表一个铜...
  • u011028655
  • u011028655
  • 2015年02月10日 17:06
  • 4835

Building a Computer Mahjong Player

  • 2016年12月15日 13:38
  • 1.16MB
  • 下载

mahjong源码

  • 2013年08月10日 16:33
  • 5.68MB
  • 下载

mahjong_sourcecode

  • 2008年11月07日 09:42
  • 5.65MB
  • 下载

Mahjong.Suit-ALI213.rar

  • 2015年12月26日 10:46
  • 19.13MB
  • 下载

麻将 (Mahjong) 源码

  • 2009年04月24日 21:19
  • 362KB
  • 下载

HDU 4431 Mahjong (麻将、神坑模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4431 题面: Mahjong Time Limit: 4000/2000 MS (J...
  • David_Jett
  • David_Jett
  • 2015年07月27日 18:32
  • 1425

uva 11210 - Chinese Mahjong(暴力搜索)

uva 11210 - Chinese Mahjong(暴力搜索)
  • zjzytnn
  • zjzytnn
  • 2016年12月05日 15:04
  • 208
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Mahjong
举报原因:
原因补充:

(最多只允许输入30个字)