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类型

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

相关文章推荐

Building a Computer Mahjong Player

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

mahjong源码

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

【jzoj4833】【Mahjong】【搜索】

题目大意解题思路暴力,先考虑顺子,再考虑四带,三带,对子,单牌,加点最优性剪枝即可。code#include #include #include #include #include #include ...

mahjong_sourcecode

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

Mahjong.Suit-ALI213.rar

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

zoj Nov. 2012 月赛 F题 Japanese Mahjong III

Japanese Mahjong III Time Limit: 2 Seconds Memory Limit: 65536 KB Mahjong is a game of skil...

麻将 (Mahjong) 源码

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

NOIPTGA组T3 Mahjong

题意:不知道怎么说。。。。。。 这不跟斗地主一样。。xjb乱搜索,超不喜欢这种题。。。因为我自带技能代码量*1.5var b,a,c,s:array[0..10,0..100]of lo...

zoj 3669 Japanese Mahjong I

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3669 题目大意:就是给你一副牌,问你胡牌的方式有几种,并输出方式...

HDU 4431 Mahjong

HDU 4431 Mahjong题目描述 Japanese Mahjong is a four-player game. The game needs four people to sit arou...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Mahjong
举报原因:
原因补充:

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