Oracle
Time limit:8000/4000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 122 Accepted Submission (s): 53
Problem Descriptionthere is once a king and queen, rulers of a unnamed city, who has three daughters of conspicuous beau Ty.
The youngest and most beautiful are psyche, whose admirers, neglecting the proper worship of the love Goddess Venus, Instea D pray and make offerings to her. Her father, the king, was desperate to know on her destiny, so he comes to the Delphi Temple to ask for a oracle.
The Oracle is an integerN without leading zeroes.
To get the meaning, he needs to rearrange the digits and split the number into <b>two positive integers without leads ing Zeroes</b>, and their sum should be as large as possible.
Help him the maximum sum. It might is impossible to does that. If So, print ' uncertain '.
Inputthe first line of the input contains an integerT (1≤T≤) , which denotes the number of test cases.
For each test case, the contains a integer n (1≤n<10000000) .
Outputfor each test case, print a positive integer or a string ' uncertain '.
Sample Input31122331
Sample Output2235uncertainHintIn the first example, it's optimal to split $ $ $ A $ $ $ and $1 $, and their sum is $21 + 1 = 22 $. In the second example, it's optimal to split $233 $ into $2 $ and $ A $, and their sum is $2 + 33 = 35 $. In the third example, it's impossible to split a digit $1 $ into the parts.
Greedy strategy simulation just fine. Put the big one in front, record the smallest number of non-0 digits and divide the smallest non-0 number. With the rest of the sum is the largest ...
Attached to my stupid code
/************************************************author:guanjuncreated time:2016/7/17 18:53:46File Name: bc2nd_a.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 10010#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespaceStd;priority_queue<int,vector<int>,greater<int> >PQ;structnode{intx, y;};structcmp{BOOL operator() (Node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x; }};BOOLcmpCharACharb) { returnA>b;}Chars[10000010];inta[10000010];vector<int>v;intMain () {#ifndef Online_judge//freopen ("In.txt", "R", stdin); #endif //freopen ("OUT.txt", "w", stdout); intT; CIN>>T; while(t--) {scanf ("%s", s); V.clear (); CLE (a); intn=strlen (s); if(n==1) puts ("uncertain"); Else{sort (s,s+N); intnum=0; intb,x; intmark=0; for(intI=0; i<n;i++) {A[i]=s[i]-'0'; if(a[i]>0) num++; if(a[i]>0&&!Mark) {b=a[i];mark=1; X=i; } } if(num==1) {puts ("uncertain");Continue; } //cout<<b<<endl; if(x!=0) a[0]+=b; Elsea[1]+=b; for(intI=0; i<n;i++){ if(i==x)Continue; if(a[i]>=Ten) {A[i]=a[i]%Ten; if((i+1)!=x) a[i+1]++; Elsea[i+2]++; } v.push_back (A[i]); } if(a[n]!=0) V.push_back (A[n]); for(intI=v.size ()-1; i>=0; i--) {printf ("%d", V[i]); } puts (""); } } return 0;}
HDU 5718 Oracle