2019 计蒜之道 复赛 B. 个性化评测系统 (模拟,实现,暴搜)

24.02% 1000ms 262144K
“因材施教”的教育方式自古有之,互联网时代,要实现真正意义上的个性化教育,离不开大数据技术的扶持。VIPKID 英语 2020 多万学员每月在课前预习、课中教学、课后复习、作业、答题测评等环节会产生超过 100100 TB 的数据增量,在对庞大数据进行分析之后,个性化评测系统会自动生成针对每个学生的量化学习报告和个性化学习图谱。

正在拿着自己的个性化学习图谱总结分析的 Dino,看到走来的小明手中拿的麻将牌,心生一题,给小明出了一道难题:“你知道怎么输出听牌吗?”看到复杂的规则,小明皱起了眉毛,请你一起来帮小明解决吧!请看题:

在麻将游戏中,有 3434 种牌,分别是 1-91−9 的万,1-91−9 的筒,1-91−9 的条,以及 77 种字牌 “东”,“南”,“西”,“北”,“白”,“发”,“中”。

这 3434 种牌各四张,共 136136 张。

如果你手牌中凑够了 1414 张牌,满足一定的牌型条件,就称作“和牌”。

这个牌型有很多种,但在本题中,只考虑最基本的一种,44 个面子 + 11 个雀头组成的牌型。

面子是刻子和顺子的统称,雀头是对子。

刻子指的是,三张一样的牌。

顺子指的是,三张连续的牌,注意,只有非字牌(也就是万,筒,条)才能连续,例如一二三万,四五六筒,并且不能循环连续,比如九一二条就不算顺子。

对子指的是,两张一样的牌。

现在,zcy 手中有 1313 张牌,并且再得到某一张牌,就可以和牌,而你的目标就是输出能使 zcy 和牌的牌。

注意一种特殊情况,如果你手牌中某张牌有四张,而再得到这张牌也能和牌,这张牌在本题中不需要输出,因为这张牌总共就只有四张,不可能拿到手了。

(如果你知道什么是杠,请假装不能杠,如果你不知道,那就不需要知道了。)

输入格式
1-91−9 万用对应数字 + 一个小写 mm 表示

​1-91−9 条用对应数字 + 一个小写 ss 表示

​1-91−9 筒用对应数字 + 一个小写 pp 表示

​东南西北白发中分别用 1-71−7 的数字 + 一个小写 zz 表示

​输入多组数据,每组共 1313 个数字 + 字母的组合,用空格隔开

​输入保证有解

输出格式
对于每组数据,输出若干行,每行一个听牌,按照万,条,筒,字的顺序输出听牌,同类型按照数从小到大输出

数据组数不超过 1010 组

样例输入 复制
1s 2s 3s 4s 5s 6s 7s 8s 9s 1z 1z 3p 4p
样例输出 复制
2p
5p

题意:

思路:
用map把给定的13个的信息存储起来,然后枚举每一种牌为听牌,如果已有了4个,则不能继续加这个牌,否则就加这个牌去判断是否能和,能和就输出,否则不输出这个牌。
判断过程我是这样写的:
先枚举所有个数大于等于2的牌,减去两张这个牌(把它当成雀头|对子),然后去看剩下的12张牌是否能凑成4个顺子或者刻子,这一步我是对每一个类型的牌,从1到9枚举,如果个数大于等于三,先取出一个刻子,然后在根据后两个牌的个数信息确定是否能凑出顺子,因为我们从1到9的顺序去枚举,所以不用考虑一个牌个数大于等于3的时候是当刻子还是顺子,因为从1开始的时候,如果1的个数大于等于3,那么如果他能凑出三个顺子,那么也可以凑出三个刻子,所以忽略影响。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char num;
char t;
map<pair<char,int>,int> m;
bool dfs()
{
	map<pair<char,int>,int> f=m;
	int res=0;
	char lx;
	int shu;
	lx='m';
	repd(i,1,9)
	{
		shu=i;
		if(f[mp(lx,shu)]>=3)
        {
            res++;
            f[mp(lx,shu)]-=3;
        }
		while(f[mp(lx,shu)]<=2&&f[mp(lx,shu)]>=1)
		{
			if(f[mp(lx,shu+1)]>=1&&f[mp(lx,shu+2)]>=1)
			{
				f[mp(lx,shu)]-=1;
				f[mp(lx,shu+1)]-=1;
				f[mp(lx,shu+2)]-=1;
				res++;
			}else
                break;
		}
	}
	lx='s';
	repd(i,1,9)
	{
		shu=i;
		if(f[mp(lx,shu)]>=3)
        {
            res++;
            f[mp(lx,shu)]-=3;
        }
		while(f[mp(lx,shu)]<=2&&f[mp(lx,shu)]>=1)
		{
			if(f[mp(lx,shu+1)]>=1&&f[mp(lx,shu+2)]>=1)
			{
				f[mp(lx,shu)]-=1;
				f[mp(lx,shu+1)]-=1;
				f[mp(lx,shu+2)]-=1;
				res++;
			}else
                break;
		}
	}
	lx='p';
	repd(i,1,9)
	{
		shu=i;
		if(f[mp(lx,shu)]>=3)
        {
            res++;
            f[mp(lx,shu)]-=3;
        }
		while(f[mp(lx,shu)]<=2&&f[mp(lx,shu)]>=1)
		{
			if(f[mp(lx,shu+1)]>=1&&f[mp(lx,shu+2)]>=1)
			{
				f[mp(lx,shu)]-=1;
				f[mp(lx,shu+1)]-=1;
				f[mp(lx,shu+2)]-=1;
				res++;
			}else
                break;
		}
	}
	lx='z';
	repd(i,1,7)
	{
		shu=i;
		if(f[mp(lx,shu)]>=3)
		{
			f[mp(lx,shu)]-=3;
			res++;
		}
	}
	return res>=4;
}
bool check()
{
	char lx;
	int shu;
	lx='m';
	repd(i,1,9)
	{
		shu=i;
		if(m[mp(lx,shu)]>=2)
		{
			m[mp(lx,shu)]-=2;
			if(dfs())
			{
			    m[mp(lx,shu)]+=2;
				return 1;
			}
			m[mp(lx,shu)]+=2;
		}
	}
	lx='s';
	repd(i,1,9)
	{
		shu=i;
		if(m[mp(lx,shu)]>=2)
		{
			m[mp(lx,shu)]-=2;
			if(dfs())
			{
			    m[mp(lx,shu)]+=2;
				return 1;
			}
			m[mp(lx,shu)]+=2;
		}
	}
	lx='p';
	repd(i,1,9)
	{
		shu=i;
		if(m[mp(lx,shu)]>=2)
		{
			m[mp(lx,shu)]-=2;
			if(dfs())
			{
			    m[mp(lx,shu)]+=2;
				return 1;
			}
			m[mp(lx,shu)]+=2;
		}
	}
	lx='z';
	repd(i,1,7)
	{
		shu=i;
		if(m[mp(lx,shu)]>=2)
		{
			m[mp(lx,shu)]-=2;
			if(dfs())
			{
			    m[mp(lx,shu)]+=2;
				return 1;
			}
			m[mp(lx,shu)]+=2;
		}
	}
	return 0;
}
int main()
{
    //freopen("D:\code\text\input.txt","r",stdin);
	//freopen("D:\code\text\output.txt","w",stdout);
	while(cin>>num>>t)
	{
		m.clear();
		int n=num-'0';
		m[mp(t,n)]++;
		repd(i,2,13)
		{
			cin>>num>>t;
			n=num-'0';
			m[mp(t,n)]++;
		}
		t='m';
		repd(i,1,9)
		{
			n=i;
			if(m[mp(t,n)]<4)
			{
				m[mp(t,n)]++;
				if(check())
				{
					cout<<n<<t<<endl;
				}
				m[mp(t,n)]--;
			}
		}
		t='s';
		repd(i,1,9)
		{
			n=i;
			if(m[mp(t,n)]<4)
			{
				m[mp(t,n)]++;
				if(check())
				{
					cout<<n<<t<<endl;
				}
				m[mp(t,n)]--;
			}
		}
		t='p';
		repd(i,1,9)
		{
			n=i;
			if(n==3)
            {
                n=3;
            }
			if(m[mp(t,n)]<4)
			{
				m[mp(t,n)]++;
				if(check())
				{
					cout<<n<<t<<endl;
				}
				m[mp(t,n)]--;
			}
		}
		t='z';
		repd(i,1,7)
		{
			n=i;
			if(m[mp(t,n)]<4)
			{
				m[mp(t,n)]++;
				if(check())
				{
					cout<<n<<t<<endl;
				}
				m[mp(t,n)]--;
			}
		}

	}




    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '
');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}


本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
原文地址:https://www.cnblogs.com/qieqiemin/p/11040425.html