You have a set of birthday cake candles. Each of such candles represents a digit between 00 and 99, inclusive.
Example of birthday cake candles.
Let's denote the candle representing the digit dd as dd-candle.
Your set contains c0c0 instances of 00-candles, c1c1 instances of 11-candles and so on. So, the total number of candles is c0+c1+⋯+c9c0+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=1c0=c1=⋯=c9=1), you can compose any number from 11 to 1010 using this set, but you cannot compose 1111.
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 yy such that all numbers from 11 to y−1y−1 can be composed by digits from your set, but yy cannot be composed.
Input
The first line contains an integer tt (1≤t≤1041≤t≤104) — the number of test cases in the input.
The only line of each test case contains ten integer numbers c0,c1,…,c9c0,c1,…,c9 (0≤ci≤1050≤ci≤105) — the number of 00-candles, 11-candles, 22-candles and so on.
It is guaranteed that the sum of all cici in the input does not exceed 106106.
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
这一题主要没有AC的原因是自己没有看懂题意,我当时很憨憨我以为题意是相加,但是这一道题的意思是这几个数字的组成,这几个数字能组成哪些数字 暂时先不考虑0 考虑其他的数字,如果数字7的数量是3个 其余的数字数量都比7大,那么这些数字中组不成最小的数字应该是7777,然后再继续往下想那么如果要考虑到0呢??你会发现这一题的隐藏输入的条件就是不能输出单个0,比如现在0和1这两个数字的数量都是最小的都是2个,那么最小的应该是111而不是1000因此当0的数量>=除了0之外所有数字的数量的最小值时,输出最小数字。反之先输出一个1再输出0.具体代码如下
#include<bits/stdc++.h>
using namespace std;
long long a[99];
int main()
{
long long t;
cin>>t;
while(t--)
{
memset(a,0,sizeof(a));
long long k=0;
long long min=10000000;
for(long long i=0;i<10;i++)
{
cin>>a[i];
}
for(long long i=1;i<10;i++)
{
if(min>a[i])
{
min=a[i];
k=i;
}
}
if(a[0]>=min)
{
for(long long i=0;i<=min;i++)
{
cout<<k;
}
cout<<endl;
}
else
{
cout<<1;
for(long long i=0;i<=a[0];i++)
{
cout<<0;
}
cout<<endl;
}
}
return 0;
}