题目链接:

Oracle

Time Limit: 8000/4000 MS (Java/Others)   

 Memory Limit: 262144/262144 K (Java/Others)

Problem Description
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`.

 
Input
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).

 
Output
For each test case, print a positive integer or a string `Uncertain`.
 
Sample Input
3
112
233
1
 
Sample Output
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[N];
int flag[11],ans[N]; 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;
}

  

hdu-5718 Oracle(水题)的更多相关文章

  1. hdu 5210 delete 水题

    Delete Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...

  2. hdu 1251 (Trie水题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  3. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

  4. HDU 4493 Tutor 水题的收获。。

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...

  5. hdu 4802 GPA 水题

    GPA Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...

  6. hdu 5718 Oracle 高精度

    Oracle Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem ...

  7. hdu 4493 Tutor 水题

    Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...

  8. hdu 5495 LCS 水题

    LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...

  9. HDU 5718 Oracle(高精度)

    Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description There ...

  10. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

随机推荐

  1. TCP No-Delay

    Nagle 算法 由于TCP中包头的大小是固定的,所以在数据(Payload)大小很小的时候IP报文的有效传输率是很低的,Nagle算法就是将多个即将发送的小段的用户数据,缓存并合并成一个大段数据时, ...

  2. css可见性

    overflow:hidden:       溢出隐藏 visibility:hidden:        隐藏元素,隐藏之后还占据原来的位置 display:none:            隐藏元 ...

  3. HTML5 这些你全知道吗?

    今天心情烦躁,搭建个论坛各种失败,Laravel.React也学不进去,于是就复习复习学过的.记录一下很少用的东西. 代码摘抄于W3C菜鸟教程HTML5手册 # 定义文本方向 <element ...

  4. 配置 yum 源相关

    1. 修改yum配置 http://www.cnblogs.com/shuaixf/archive/2011/11/30/2268496.html 2. centos安装 epel 源 https:/ ...

  5. SolidEdge 如何绘制断裂剖视图 局部剖视图

    1 点击局部放大图,然后点击绘制按钮,然后点击选择要绘制的视图   2 绘制封闭的局部剖视图的剖面线(必须封闭,点击最后一个点封闭之后会变成蓝色虚线)   3 修改深度(不一定要在下图的右下角修改深度 ...

  6. libxml/HTMLparser.h file not found

    在导入asihttprequest包时出问题导入了libxml2.dylib.可是却提示libxml/HTMLparser.h file not found. 这是由于你的开发环境默认的路径无法找到这 ...

  7. LeetCode——Remove Nth Node From End of List

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  8. JSP简明教程:汇总

    原创JSP教程,简洁明了,不含废话. JSP简明教程(一):JSP简单介绍 JSP简明教程(二):JSP基本的语法 JSP简明教程(三):JSP隐含对象 JSP简明教程(四):EL表达式语言.Java ...

  9. java涉及父子类的异常

    java中的异常涉及到父子类的问题,可以归纳为一句话:子类的构造函数抛出的异常必须包含父类的异常,子类的方法可以选择抛出“范围小于等于”父类的异常或不抛出异常. 1. 为什么构造函数必须抛出包含父类的 ...

  10. 流媒体开发之开源项目live555---live555 server 编译 包括更改帧率大小

    由于要测试8148解码器的性能,需要搭建不同帧率25fps - >30fps,宏块大小defualt 100 000 -> 200 000不同大小的h264码流,所以就需要编译改动的liv ...