hdu-5718 Oracle(水题)
2016-07-18 10:10
309 查看
题目链接:
Memory Limit: 262144/262144 K (Java/Others)
[align=left]Problem Description[/align]
There is once a king and queen, rulers of an unnamed city, who have three daughters of conspicuous beauty.
The youngest and most beautiful is Psyche, whose admirers, neglecting the proper worship of the love goddess Venus, instead pray and make offerings to her. Her father, the king, is desperate to know about her destiny, so he comes to the Delphi Temple to ask for an oracle.
The oracle is an integer n without leading zeroes.
To get the meaning, he needs to rearrange the digits and split the number into <b>two positive integers without leading zeroes</b>, and their sum should be as large as possible.
Help him to work out the maximum sum. It might be impossible to do that. If so, print `Uncertain`.
[align=left]Input[/align]
The first line of the input contains an integer T (1≤T≤10), which denotes the number of test cases.
For each test case, the single line contains an integer n (1≤n<10^10000000).
[align=left]Output[/align]
For each test case, print a positive integer or a string `Uncertain`.
[align=left]Sample Input[/align]
3
112
233
1
[align=left]Sample Output[/align]
22
35
Uncertain
题意:
给一个大数,拆成两个没有前导0的数,使其和最大;
思路:
贪心,可知应该把大于0的最小数当做单独的那一个数,这样才能保证最大;然后就是一个大数加法;
AC代码:
Oracle
Time Limit: 8000/4000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others)
[align=left]Problem Description[/align]
There is once a king and queen, rulers of an unnamed city, who have three daughters of conspicuous beauty.
The youngest and most beautiful is Psyche, whose admirers, neglecting the proper worship of the love goddess Venus, instead pray and make offerings to her. Her father, the king, is desperate to know about her destiny, so he comes to the Delphi Temple to ask for an oracle.
The oracle is an integer n without leading zeroes.
To get the meaning, he needs to rearrange the digits and split the number into <b>two positive integers without leading zeroes</b>, and their sum should be as large as possible.
Help him to work out the maximum sum. It might be impossible to do that. If so, print `Uncertain`.
[align=left]Input[/align]
The first line of the input contains an integer T (1≤T≤10), which denotes the number of test cases.
For each test case, the single line contains an integer n (1≤n<10^10000000).
[align=left]Output[/align]
For each test case, print a positive integer or a string `Uncertain`.
[align=left]Sample Input[/align]
3
112
233
1
[align=left]Sample Output[/align]
22
35
Uncertain
题意:
给一个大数,拆成两个没有前导0的数,使其和最大;
思路:
贪心,可知应该把大于0的最小数当做单独的那一个数,这样才能保证最大;然后就是一个大数加法;
AC代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar()); for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + '0'); putchar('\n'); } const LL mod=1e9+7; const double PI=acos(-1.0); const int inf=1e9; const int N=1e7+10; const int maxn=1e3+10; const double eps=1e-6; char s ; int flag[11],ans ; int main() { int t; read(t); while(t--) { mst(flag,0); scanf("%s",s); int len=strlen(s),num=0; For(i,0,len-1)if(s[i]=='0')num++; if(num==len-1)cout<<"Uncertain\n"; else { int mmin=9; For(i,0,len-1)flag[s[i]-'0']++; For(i,1,9) { if(flag[i]){flag[i]--,mmin=i;break;} } int cnt=0; for(int i=0;i<=9;i++) while(flag[i]--)ans[++cnt]=i; ans[1]+=mmin; ans[len]=0; for(int i=1;i<=len-1;i++) { ans[i+1]+=ans[i]/10; ans[i]=ans[i]%10; } if(ans[len])printf("%d",ans[len]); for(int i=len-1;i>0;i--)printf("%d",ans[i]); printf("\n"); } } return 0; }
相关文章推荐
- 7-16 Bestcoder a Oracle
- 利用函数返回oracle对象表的三种方法
- oracle之order by
- python读取oracle函数返回值
- FIREDAC驱动ORACLE的配置
- oracle基础复习-2016.7.18
- python读取oracle函数返回值
- 利用函数返回oracle对象表的三种方法
- Oracle 数据泵是干什么的
- oracle/hive数据互导
- oraclelinux
- HDU 5718 Oracle
- hdu_5718_Oracle(大数模拟)
- hdu_5718_Oracle(大数模拟)
- hdu 5718 Oracle(模拟)
- hdu 5718 Oracle 高精度
- Oracle【BC】
- BestCoder 2nd Anniversary - 1001 Oracle
- 21.Which three statements are true about logical structures of the Oracle database? (Choose three.)
- ORACLE基本数据类型总结