Happy Birthday CodeForces - 1250H(贪心)

You have a set of birthday cake candles. Each of such candles represents a digit between 0 and 9, inclusive.
在这里插入图片描述
Example of birthday cake candles.
Let’s denote the candle representing the digit d as d-candle.

Your set contains c0 instances of 0-candles, c1 instances of 1-candles and so on. So, the total number of candles is c0+c1+⋯+c9.

These digits are needed to wish your cat a happy birthday. For each birthday, starting with the first, you want to compose the age of the cat using the digits from the set.

Since you light candles for a very short time, candles don’t have time to burn out. For this reason you can reuse candles an arbitrary number of times (therefore your set of candles never changes).

For example, if you have one instance of each digit (i.e. c0=c1=⋯=c9=1), you can compose any number from 1 to 10 using this set, but you cannot compose 11.

You have to determine the first birthday, on which you cannot compose the age of the cat using the candles from your set. In other words, find the minimum number y such that all numbers from 1 to y−1 can be composed by digits from your set, but y cannot be composed.

Input
The first line contains an integer t (1≤t≤104) — the number of test cases in the input.

The only line of each test case contains ten integer numbers c0,c1,…,c9 (0≤ci≤105) — the number of 0-candles, 1-candles, 2-candles and so on.

It is guaranteed that the sum of all ci in the input does not exceed 106.

Output
For each test case, output one integer in single line — the minimum age which cannot be composed by candles from your set. Please note that the age can be quite large (it may exceed the standard 64-bit integer types in your programming language).

Example
Input
4
1 1 1 1 1 1 1 1 1 1
0 0 1 1 2 2 3 3 4 4
1 2 1 2 1 3 1 0 0 0
0 1 2 1 4 3 1 1 2 1
Output
11
1
7
10
思路:最小不能组成的数字,肯定是由短板造成的,那么我们就寻找位置靠前并且数目最少的数字,如果是0的话,前面加一个1.之后就输出c[i]+1个数字就好了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;

const int maxx=1e1+10;
int c[maxx];
int n;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		n=10;
		for(int i=0;i<10;i++) scanf("%d",&c[i]);
		c[10]=c[0];
		int _max=inf;
		int pos;
		for(int i=1;i<=n;i++) if(c[i]<_max) _max=c[i],pos=i%10;
		if(pos==0) cout<<1;
		for(int i=1;i<=c[pos]+1;i++) cout<<pos;
		cout<<endl;
	}
	return 0;
}

努力加油a啊,(o)/~

发布了617 篇原创文章 · 获赞 64 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/starlet_kiss/article/details/105261557