HDU 5718 Oracle(高精度)
Time Limit:4000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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
For each test case, the single line contains an integer $ n $ $ (1 \le n < 10 ^ {10000000}) $.
Output
Sample Input
3
112
233
1
Sample Output
22
35
Uncertain
Hint
In the first example, it is optimal to split $ 112 $ into $ 21 $ and $ 1 $, and their sum is $ 21 + 1 = 22 $. In the second example, it is optimal to split $ 233 $ into $ 2 $ and $ 33 $, and their sum is $ 2 + 33 = 35 $. In the third example, it is impossible to split single digit $ 1 $ into two parts.
#include<cstdio>
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 10000005
char s[N];
int main()
{
int T,len,minn,mi,i;
scanf("%d",&T);
while(T--)
{
scanf("%s",&s);
len=strlen(s);
sort(s,s+len);
if(len==||s[len-]=='')
printf("Uncertain\n");
else
{
for( i=;i<len;i++)
if(s[i]!='')
{
minn=i;
mi=s[i]-'';
break;
}
for(i=minn;i>;i--)
s[i]=s[i-];//接下来都是从1开始
s[]+=mi;
for(i=;i<len-;i++)
{
if(s[i]>'')
{
s[i+]++;
s[i]-=;
}
else
break;
}
printf("%d",s[len-]-'');
for(i=len-;i>=;i--)
printf("%c",s[i]);
printf("\n");
}
}
return ;
}
HDU 5718 Oracle(高精度)的更多相关文章
- hdu 5718 Oracle 高精度
Oracle Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Problem ...
- hdu 5718(Oracle)大数加法
曾经有一位国王,统治着一片未名之地.他膝下有三个女儿. 三个女儿中最年轻漂亮的当属Psyche.她的父亲不确定她未来的命运,于是他来到Delphi神庙求神谕. 神谕可以看作一个不含前导零的正整数n n ...
- HDU 5718 Oracle
如果非零的数小于等于1个,则无解.否则有解. 取出一个最小的非零的数作为一个数,剩下的作为一个数,相加即可. #include<cstdio> #include<cstring> ...
- BestCoder 2nd Anniversary/HDU 5718 高精度 模拟
Oracle Accepts: 599 Submissions: 2576 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/26 ...
- Hdu 5568 sequence2 高精度 dp
sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...
- hdu 1042 N!(高精度乘法 + 缩进)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...
- HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)
Sum Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u Submit Status ...
- hdu 1042 N!(高精度乘法)
Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in ...
- HDU 5047 Sawtooth 高精度
题意: 给出一个\(n(0 \leq n \leq 10^{12})\),问\(n\)个\(M\)形的折线最多可以把平面分成几部分. 分析: 很容易猜出来这种公式一定的关于\(n\)的一个二次多项式. ...
随机推荐
- CentOS 7 引导 -- GRUB2
如果安装完 CentOS 7 之后,原来的 Windows 引导菜单被覆盖了,vi /boot/grub2/grub.cfg 添加如下代码: ## BEGIN WINDOWS 10 menuentry ...
- 关于jquery 1.9以上多次点击checkbox无法选择的
在jquery1.9之前,我们对于一个checkbox对象来进行重复选择或者取消, 我们可以使用这个方法$().attr('checked',checked);//选中 $().removeAttr( ...
- [SQL基础教程] 4-3 数据的更新(UPDATE)
[SQL基础教程] C4 数据更新 4-3 数据的更新(UPDATE) UPDATE UPDATE <表名> SET <列名> = <表达式>; UPDATE &l ...
- HDU 4403 A very hard Aoshu problem(DFS)
A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...
- cdh 安装记录
安装文件准备 CDH 下载地址:http://archive.cloudera.com/cdh5/parcels/latest/ 下载操作系统对应的版本: 1.CDH-5.3.0-1.cdh5.3.0 ...
- 【故障】当Eclipse打不开的时候
某天,当你打开Eclipse的时候,弹出这种路径错误的界面.那么,该怎么办呢??? 参考: https://zhidao.baidu.com/question/1497777962705951219. ...
- Python3 md5加密
import hashlibuser = 'jointwisdom'pwd = 'zhonghui123'm2 = hashlib.md5()m2.update(pwd.encode("ut ...
- canvas画扇形图(本文来自于http://jo2.org/html5-canvas-sector/)
1.定义画扇形的构造函数: //扇形CanvasRenderingContext2D.prototype.sector = function (x, y, radius, sDeg, eDeg) {/ ...
- js数组操作-打乱数组
<style> html, body { margin: 0; padding: 0;} div span { display: inline-block; width: 25px; he ...
- redis介绍。
1. Redis是什么 这个问题的结果影响了我们怎么用Redis.如果你认为Redis是一个key value store, 那可能会用它来代替MySQL;如果认为它是一个可以持久化的cache, 可 ...