the code of the OracleTime limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others)Submit Status
The Oracle is one of the training team's most intelligent minds, storing what he is learning in his computer. Every day through learning to improve their knowledge level. However, as an elder, the Oracle does not want to his own learning materials to those too young, too simple, sometimes naive, so as not to be seen by them to engage in a big news. The Oracle then sets the password for his own computer.
Of course, he sets the password to follow the Basic Law as well. The Basic Law was made by the Oracle himself. The law is this:
1, the password is composed of 2 n digits, the middle is separated by a space, wherein, two number of each bit and all are s
2, is to meet the minimum number of 1 conditions and the largest number
3, when unable to find n number of bits and s, the password is: -1-1 .
4, Oracle guarantee the password of 2 number of no leading 0.
He this password only to prevent too young, too simple, sometimes naive people into the computer, for you these high IQ of the crowd, deciphering the password should not be difficult it ~ ~
Note that the individual 0, is legal oh ~
Input
First read into a t(0≤t≤), the number of data groups
There is only one row for each set of data,N(0<n≤ ) and s(0≤s≤).
Output
Output the Oracle's password
Sample Input and output
| Sample Input |
Sample Output |
12 15 |
69 96 |
Hint
Just a set of test data 2 number of digits for The maximum value for the is 9 6 , minimum value is < Span id= "mathjax-span-124" class= "math" > 69 .
The main problem: WA for one hours, the question can be divided into two steps, the first to find the smallest, then the largest, the smallest to meet the previous number as small as possible but the first bit can not be 1, the largest to meet the previous number as large as possible,
If this n bits per bit is 9 and is also less than s or is not satisfied, if n is greater than 1,s equals 0 is not satisfied; then greedy to find out the value of each bit; mainly consider full details
Code:
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>using namespacestd;#defineMem (x, y) Memse (x,y,sizeof (x))#defineSI (x) scanf ("%d", &x)#definePI (x) printf ("%d", X)#defineP_ printf ("")Const intmaxn=1010;intA[MAXN];intMain () {intt,n,s; SI (T); while(t--) {SI (n); SI (s); if(9*n<s) {Puts ("-1-1");Continue; } if(s==0&&n>1) {puts ("-1-1");Continue; } if(s==0&&n==1) {puts ("0 0");Continue; } inttemp=s; if(s>9* (n1)) a[n]=s-9* (n1), s-=s-9* (n1); Elsea[n]=1, s-=1; for(inti=n-1; i>=1; i--){ if(s>9* (I-1)) a[i]=s-9* (I-1), s-=s-9* (I-1); Elsea[i]=0; } for(intI=n;i>0; i--) PI (A[i]); P_; S=temp; for(inti=n;i>=1; i--){ if(s>=9) a[i]=9, s-=9; Elsea[i]=s,s-=s; //printf ("**%d\n", s); } for(intI=n;i>0; i--) PI (A[i]); Puts (""); } return 0;}
Oracle's code (thinking)