BNU Contest 8-26 F. Japanese Mahjong III

BNU Contest 8-26 F. Japanese Mahjong III

BNU Contest 8-26 竞赛题目链接点击这里

F. Japanese Mahjong III

Time Limit: 2000ms
Memory Limit: 65536KB

64-bit integer IO format: %lld      Java class name: Main

Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this problem, we concentrate on Japanese Mahjong, a variation of mahjong. For brief, all of the word mahjong mentioned following refer to Japanese Mahjong.



Japanese mahjong is usually played with 136 tiles, which can be organized into several categories:



  • Suited tiles. All suited tiles are of a rank and a suit.There are three suits of tiles, with ranks ranging from one to nine. There are four tiles of each rank and suit combination, thus there are 36 tiles in a suit, and 108 suited tiles in total.
    • The circle suit
    • The bamboo suit
    • The character suit
  • Honor tiles. Honor Tiles are tiles that do not have a rank or suit. They are divided into two categories. There are four types of Wind tiles and three types of Dragon tiles, with four of each type of honor tile. Thus, there are 16 wind tiles and 12 Dragon tiles for 28 honor tiles.
    • Wind tiles. The Wind tiles consist of four kinds of tile: East, South, West, and North.
    • Dragon tiles. The Dragon titles consist of three types of tile: Red, Green, White.

In this problem, we introduce two abnormal kinds of winning hand different from the normal winning hand, which consist of four melds and one eyes.

  1. Seven Pairs: the hand consists of seven different pairs. No two pairs are the same. For example:
  2. Thirteen Orphans: the hand consists of thirteen kinds of tiles: Circle One, Circle Nine, Bamboo One, Bamboo Nine, Character One, Character Nine, East, South, West, North, Red, Green and White. Only one kind of them are two tiles, while the others are all only one tile. For example:

Now, given a hand with 14 tiles, can you answer this hand is which kind of abnormal kind of winning hand?


There are multiple cases. Each case consists of 28 characters in one line, describing 14 tiles. The manner for describing each type of tile is:

  • Two characters stand for one tile.
  • For Suited tiles, the first is a integer ranged from one to nine, the tile’s rank, and the second is a character: ‘p’ for the circle suit, ‘s’ for the bamboo suit, and ‘m’ for the character suit.
  • For Honor tiles, the first is a integer: from one to seven stands for East, South, West, North, White, Green, and Red respectively. The second one is always ‘z’.

We promise that the input is a legal hand, which means there isn’t another type of tiles described above or there are more than four same tiles.


For each case, if the hand is Seven Pairs, output “Seven Pairs”. If the hand is Thirteen Orphans, output “Thirteen Orphans”. If the hand is neither Seven Pairs nor Thirteen Orphans, output “Neither!”.

Sample Input


Sample Output

Seven Pairs
Thirteen Orphans

题目大意:给你一个麻将序列 问你这个序列是不是SevenPairs或者 Thirteen Orphans 还有可能都不是

这题是很明显的水题 。。。建立一个结构体把牌排下序,然后判断一下就可以了 只有判断的时候有一点点技巧

技巧看代码就能看懂 就不解释了 = =


    > File Name: F.cpp
    > Author: VOID_133
    > QQ: 393952764
    > Mail: [email protected] 
    > Created Time: 2014年08月26日 星期二 13时02分12秒
using namespace std;

bool isSeven();
bool isOrphan();
typedef struct icard{
	int rank;
	int type;

bool cmp(const Card& c1,const Card& c2)
		return c1.type<c2.type;
	return c1.rank<c2.rank;

Card card[30];

int main(void)
	char cards[30];
		for(int i=0;i<27;i+=2)
				case 's':
				case 'm':
				case 'p':
				case 'z':

	if(isSeven()) printf("Seven Pairs");
	else if(isOrphan()) printf("Thirteen Orphans");
	else printf("Neither!");
	return 0;

bool isSeven()
	for(int i=0;i<14;i+=2)
		if(card[i].rank==card[i+1].rank && card[i].type==card[i+1].type)
				if(card[i].rank==card[i-1].rank && card[i].type==card[i-1].type)
				return false;
		else return false;
	return true;

bool isOrphan()
	int haven[13];
	for(int i=0;i<14;i++)
			//j	switch(card[i].rank)
			//j	{
			//j		case 1:

			//j	}
			if(card[i].rank==1) haven[0]++;
			if(card[i].rank==9) haven[1]++;
		else if(card[i].type==1)
			if(card[i].rank==1) haven[2]++;
			if(card[i].rank==9) haven[3]++;
		else if(card[i].type==2)
			if(card[i].rank==1) haven[4]++;
			if(card[i].rank==9) haven[5]++;
		else if(card[i].type==3)
			if(card[i].rank<=7) haven[5+card[i].rank]++;
	int two=0;
	for(int i=0;i<13;i++)
		if(haven[i]==0 || haven[i]>2 ) return false;
		if(haven[i]==2 && two) return false;
		else if(haven[i]==2)
	if(two!=0) return true;
	else return false;


Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − 8 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.