uva11210(麻将)

#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>


#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 64;
map<string, int> mj = {
	{"1T",1},{"2T",2},{"3T",3},{"4T",4},{"5T",5},{"6T",6},{"7T",7},{"8T",8},{"9T",9},
	{"1S",11},{"2S",12},{"3S",13},{"4S",14},{"5S",15},{"6S",16},{"7S",17},{"8S",18},{"9S",19},
	{"1W",21},{"2W",22},{"3W",23},{"4W",24},{"5W",25},{"6W",26},{"7W",27},{"8W",28},{"9W",29},
	{"DONG",31},{"NAN",32},{"XI",34},{"BEI",35},{"ZHONG",37},{"FA",38},{"BAI",40}
};
vector<string> mj2(64);
int cnt[maxn],input[maxn],n;

bool search(int d) {
	if (d == 4) return true;
	for (int i = 0; i < 41; i++) {
		if (cnt[i] >= 3) {
			cnt[i] -= 3;
			if (search(d + 1)) return true;
			cnt[i] += 3;
		}
	}

	for (int i = 2; i < 41; i++) {
		if (cnt[i] > 0 && cnt[i - 1] > 0 && cnt[i - 2] > 0) {
			cnt[i - 2]--;
			cnt[i - 1]--;
			cnt[i]--;
			if (search(d + 1)) return true;
			cnt[i - 2]++;
			cnt[i - 1]++;
			cnt[i]++;
		}
	}
	return false;
}
bool check() {
	for (int i = 0; i < 41; i++) {
		if (cnt[i] >= 2) {
			cnt[i] -= 2;
			if (search(0)) return true;
			cnt[i] += 2;
		}
	}
	return false;
}

int main()
{
	string name;
	int kCase = 0;
	for (auto it = mj.begin(); it != mj.end(); it++) {
		mj2[it->second] = it->first;
	}

	while (cin >> name && name != "0") {
		input[0] = mj[name];
		for (int i = 1; i < 13; i++) {
			cin >> name;
			input[i] = mj[name];
		}
		bool ok = false;
		cout << "Case " << ++kCase << ":";
		for (int j = 1; j < 41;j++) {
			if (mj2[j].empty())continue;
			memset(cnt, 0, sizeof(cnt));
			int cur = j;
			for (int i = 0; i < 13; i++)cnt[input[i]]++;
			if (cnt[cur] >= 4) continue;
			cnt[cur] ++;
			if (check()) {
				ok = true;
				cout << " " << mj2[cur];
			}
			cnt[cur]--;
		}
		if (!ok) cout << " Not ready";
		cout << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值