题目链接:

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代码:
 
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. #define For(i,j,n) for(int i=j;i<=n;i++)
  10. #define mst(ss,b) memset(ss,b,sizeof(ss));
  11.  
  12. typedef long long LL;
  13.  
  14. template<class T> void read(T&num) {
  15. char CH; bool F=false;
  16. for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
  17. for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
  18. F && (num=-num);
  19. }
  20. int stk[70], tp;
  21. template<class T> inline void print(T p) {
  22. if(!p) { puts("0"); return; }
  23. while(p) stk[++ tp] = p%10, p/=10;
  24. while(tp) putchar(stk[tp--] + '0');
  25. putchar('\n');
  26. }
  27.  
  28. const LL mod=1e9+7;
  29. const double PI=acos(-1.0);
  30. const int inf=1e9;
  31. const int N=1e7+10;
  32. const int maxn=1e3+10;
  33. const double eps=1e-6;
  34.  
  35. char s[N];
  36. int flag[11],ans[N];
  37.  
  38. int main()
  39. {
  40.  
  41. int t;
  42. read(t);
  43. while(t--)
  44. {
  45. mst(flag,0);
  46. scanf("%s",s);
  47. int len=strlen(s),num=0;
  48. For(i,0,len-1)if(s[i]=='0')num++;
  49. if(num==len-1)cout<<"Uncertain\n";
  50. else
  51. {
  52. int mmin=9;
  53. For(i,0,len-1)flag[s[i]-'0']++;
  54. For(i,1,9)
  55. {
  56. if(flag[i]){flag[i]--,mmin=i;break;}
  57. }
  58. int cnt=0;
  59. for(int i=0;i<=9;i++)
  60. while(flag[i]--)ans[++cnt]=i;
  61. ans[1]+=mmin;
  62. ans[len]=0;
  63. for(int i=1;i<=len-1;i++)
  64. {
  65. ans[i+1]+=ans[i]/10;
  66. ans[i]=ans[i]%10;
  67. }
  68. if(ans[len])printf("%d",ans[len]);
  69. for(int i=len-1;i>0;i--)printf("%d",ans[i]);
  70. printf("\n");
  71. }
  72. }
  73. return 0;
  74. }

  

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. laravel 查询构造器

    //查询构造器public function query(){ $bool = DB::table('student')->insert([ ['name' => '王五', 'age' ...

  2. JQuery select 编程时选中原有的值

    js 此为核心代码 $(document).ready(function(){ $("#carTypeId").attr("value",'${carInfo. ...

  3. spring security原理图及其解释

    用户发出订单修改页面的请求,Access Decision Manager进行拦截,然后对比用户的授权和次页面需要的授权是不是有重合的部分,如果有重合的部分,那面页面就授权成功,如果失败就通知用户. ...

  4. Mysql 性能优化20个原则(1)

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  5. 【Todo】Java类型转换总结

    参考 http://www.cnblogs.com/lwbqqyumidi/p/3700164.html 这篇文章也可以对照着看:http://www.360doc.com/content/10/09 ...

  6. U盘容纳不了大于4G的文件比如ISO文件咋办?

    格式化U盘成NTFS格式就行了,不这么做8,16,32G Upan都容纳不下来.

  7. 经典游戏“大富翁4”存档文件修改器Rich4Editor下载

    下载地址: http://files.cnblogs.com/files/xiandedanteng/Rich4Editor20170614.zip http://files.cnblogs.com/ ...

  8. linux操作系统下查看某rpm包是32bit 还是x64bit的命令

    [root@hosta ~]# rpm -qa --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" | grep l ...

  9. 心情日记app总结 数据存储+服务+广播+listview+布局+fragment+intent+imagebutton+tabactivity+美工

    ---恢复内容开始--- 结果截图如下: 第一张图是程序主界面,主要是显示记事列表的一些个事件.旁边的侧拉框是自己登陆用的.可以设置密码.可以查看反馈与关于等信息. 点击第一张图片下方的图标,会显示不 ...

  10. linux块设备驱动(一)——块设备概念介绍

    本文来源于: 1. http://blog.csdn.net/jianchi88/article/details/7212370 2. http://blog.chinaunix.net/uid-27 ...