hdu 5718 Oracle 高精度
Oracle
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
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`.
For each test case, the single line contains an integer n (1≤n<1010000000).
112
233
1
35
Uncertain
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<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 100000007
#define esp 0.00000000001
const int N=1e5+,M=1e7+,inf=1e9+;
char a[M];
char b[M];
char c[M];
void add(char a[],char b[])//a=a+b
{
int i,j,k,sum=;
k=strlen(a)>strlen(b)?strlen(a):strlen(b);
a[k+]=;
for(i=strlen(a)-,j=strlen(b)-;i>=||j>=;i--,j--,k--)
{ if(i>=) sum+=a[i]-''; if(j>=) sum+=b[j]-'';
a[k]=sum%+''; sum/=;
}
if(sum) a[]=sum+'';
else strcpy(a,&a[]);
printf("%s\n",a);
}
int check(char *a)
{
int x=strlen(a);
if(x==)
return ;
for(int i=;i<x;i++)
if(a[i]!='')
return ;
return ;
}
int flag[];
int main()
{
int x,y,z,i,t;
int T;
scanf("%d",&T);
while(T--)
{
memset(flag,,sizeof(flag));
scanf("%s",a);
x=strlen(a);
for(i=;i<x;i++)
flag[a[i]-'']++;
int ji=;
int lu=;
for(i=;i<=;i++)
if(flag[i])
{
c[lu++]=''+i;
flag[i]--;
break;
}
for(i=;i>=;i--)
{
while(flag[i]!=)
{
b[ji++]=i+'';
flag[i]--;
}
}
b[ji]='\0';
c[lu]='\0';
if(check(b)&&check(c))
add(b,c);
else
printf("Uncertain\n");
}
return ;
}
hdu 5718 Oracle 高精度的更多相关文章
- HDU 5718 Oracle(高精度)
Time Limit:4000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description There ...
- 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\)的一个二次多项式. ...
随机推荐
- BackgroundWorker
Constants.Worker = new BackgroundWorker(); Constants.Worker.WorkerSupportsCancellation = true; Const ...
- fullscreen DXGI DX11
these days i am fullfilling full screen https://github.com/rufelt/simpled3d11window put this one in ...
- Coding4Fun.Phone.Controls的使用
Coding4Fun.Phone.Controls的使用: windows phone的应用一直有一个特色,那就是方块(磁贴).之前的应用中,我一直都XXXX 来实现,原来其实一直有一个更加好的方法, ...
- Spring MVC学习问题记录
自2015年3月11日开始进行记录 day01 2015.03.11 问题1:Line 1 in XML document from URL is invalid; 今天出现了Content is n ...
- Eclipse Plugin for Hadoop
Eclipse 官网下载向导 下载 下载的安装文件放到~/setupEnv,将安装到/opt目录下 cd ~/setupEnv sudo tar zxvf eclipse-java-kepler-SR ...
- 疯狂java讲义——初始化块
- 彻底理解js中this的指向
首先必须要说的是,this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象(这句话有些问题,后面会解释为什么会有问题,虽然 ...
- APM终端用户体验监控分析(下)
一.前言 [APM 终端用户体验监控分析(上)][1]从 APM 终端用户产品特性.使用建议.以及从[真实用户体验][2]和[模拟性能监控][3]两方面入手给大家进行了简单的分享. 本文为下篇,将给大 ...
- LCS最长公共子序列(最优线性时间O(n))
这篇日志主要为了记录这几天的学习成果. 最长公共子序列根据要不要求子序列连续分两种情况. 只考虑两个串的情况,假设两个串长度均为n. 一,子序列不要求连续. (1)动态规划(O(n*n)) (转自:h ...
- awk处理之案例一:awk 处理百分比的问题
编译环境 本系列文章所提供的算法均在以下环境下编译通过. [脚本编译环境]Federa 8,linux 2.6.35.6-45.fc14.i686 [处理器] Intel(R) Core(TM)2 Q ...