现在的位置: 首页 > 综合 > 正文

Chinese Mahjong

2013年06月15日 ⁄ 综合 ⁄ 共 1785字 ⁄ 字号 评论关闭

 

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits> 
#include <set>
#include <string> 
#include <sstream>
#include <utility>
#include <ctime>
//#pragma comment(linker, "/STACK:1024000000,1024000000") 

using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::getline;
using std::make_pair;
using std::greater;

int quant[34];
int init[34];

bool dfs(int dep)
{
	if(dep == 4)
		return true;
	for(int i = 0; i < 34; ++i)
		if(quant[i] >= 3)
		{
			quant[i] -= 3;
			if(dfs(dep+1))
				return true;
			quant[i] += 3;
		}
	for(int i = 0; i < 24; ++i)
		if(i%9 <= 6 && quant[i] && quant[i+1] && quant[i+2])
		{
			--quant[i]; --quant[i+1]; --quant[i+2];
			if(dfs(dep+1))
				return true;
			++quant[i]; ++quant[i+1]; ++quant[i+2];
		}
	return false;
}

bool check()
{
	memcpy(quant, init, sizeof(quant));
	for(int i = 0; i < 34; ++i)
		if(quant[i] >= 2)
		{
			quant[i] -= 2;
			if(dfs(0))
				return true;
			quant[i] += 2;
		}
	return false;
}

char str[34][10] = {"1T", "2T", "3T", "4T", "5T", "6T", "7T", "8T", "9T",
					"1S", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S",
					"1W", "2W", "3W", "4W", "5W", "6W", "7W", "8W", "9W", 
					"DONG", "NAN", "XI", "BEI", 
					"ZHONG", "FA", "BAI"};
char temp[10];

int search(char *p)
{
	for(int i = 0; i < 34; ++i)
		if(strcmp(str[i], p) == 0)
			return i;
}

int main()
{
	int n_case(0);
	while(scanf("%s", temp), temp[0] != '0')
	{
		memset(init, 0, sizeof(init));
		++init[search(temp)];
		for(int i = 1; i < 13; ++i)
		{
			scanf("%s", temp);
			++init[search(temp)];
		}
		printf("Case %d:", ++n_case);
		bool flag(true);
		for(int i = 0; i < 34; ++i)
			if(init[i] < 4)
			{
				++init[i];
				if(check())
				{
					printf(" %s", str[i]);
					flag = false;
				}
				--init[i];
			}
		if(flag)
			printf(" Not ready");
		printf("\n");
	}
	return 0;
}

 

抱歉!评论已关闭.