gym102835B Make Numbers

https://codeforces.com/gym/102835/problem/B

当年高一24点写了200多行

直到大三暑假我才学会vector传参进函数,前几周看别人cf代码学会了next_permutation,上次天梯赛学会了map可以映射vector

这种题就随便写了

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
 
const int maxl=1e5+10;
 
int n,ans;
bool vis[maxl];
map<pair<vector<int>,int>,bool> mp;
 
inline void dfs(int stp,vector<int> a)
{
	if(mp[{a,stp}])
		return;
	mp[{a,stp}]=true;
	int l=a.size();
	if(l==1)
	{
		if(a[0]>=0 && !vis[a[0]])
		{
			vis[a[0]]=true,++ans;
			//printf("%d\n",a[0]);
		}
		return;
	}
	if(stp==1 || stp==2)
	{
		dfs(stp+1,a);
		if(stp==1 && l==2)
			return;
		for(int i=0;i<l-1;i++)
		{
			vector<int> tmp;
			for(int j=0;j<i;j++)
				tmp.pb(a[j]);
			if(stp==1)
			{
				if(a[i+1]<10)
					tmp.pb(a[i]*10+a[i+1]);
				else
					tmp.pb(a[i]*100+a[i+1]);
			}
			else
				tmp.pb(a[i]*a[i+1]);
			for(int j=i+2;j<l;j++)
				tmp.pb(a[j]);
			dfs(stp,tmp);	
		}
	}
	if(stp==3)
	{
		vector<int> tmp;
		tmp.pb(a[0]+a[1]);
		for(int i=2;i<l;i++)
			tmp.pb(a[i]);
		dfs(3,tmp);
		tmp[0]=a[0]-a[1];
		dfs(3,tmp);
	}
}
 
int main()
{
	vector<int> a;
	for(int i=1;i<=4;i++)
	{
		int x;scanf("%d",&x);
		a.pb(x);
	}
	sort(a.begin(),a.end());
	do
		dfs(1,a);
	while(next_permutation(a.begin(),a.end()));
	printf("%d\n",ans);
	/*for(int i=0;i<=1e4;i++)
	if(vis[i])
		printf("%d\n",i);
	*/
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值