小白月赛4 博弈论 ʕ •ᴥ•ʔ

铁子和顺溜在学习了博弈论的sg函数之后,解决了很多很多博弈题,现在他们遇到了一道难题。
给出一个长度为 n 的数列,数列里的每个元素都是个位数,这个数列的每一个连续子数列都能生成
一个十进制数,对于子数列a[l~r],这个十进制数的个位为a[r],十位为a[r - 1],...,最高位
为a[l]。
现在铁子需要知道最小的不能被该数列的子数列生成的十进制非负整数是多少?

输入描述:

第一行一个数字n。(1 ≤ n ≤ 1000)
第二行n个数字di。(0 ≤ di ≤ 9)

输出描述:

输出一个数字表示答案。

示例1

输入

4
3 0 1 2

输出

4

示例2

输入

10
9 8 7 6 5 4 3 2 1 0

输出

11

做题只会暴力。。。

#include <cstring>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <map>
#define ll long long
using namespace std;
#define pai acos(-1,0)
ll a[1010];
int main()
{
	map<ll,ll>mp;
	int n;
	cin>>n;
	for(int i=0;i<=1e6;i++)
	{
		mp[i]=0;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		mp[a[i]]=1;
		int z=10;
		int w=a[i];
		for(int j=i-1;j>0;j--)
		{
			w=w+z*a[j];
			z=z*10;
		
			mp[w]=1;
			if(z>1000000)
			break;
		}
	}
	for(int i=1;i<=1e9;i++)
	{
		if(!mp[i])
		{
			cout<<i<<endl;
			return 0;
		}
	}

}

猜你喜欢

转载自blog.csdn.net/henucm/article/details/82152917