HDU 5718 Oracle

Oracle

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 122    Accepted Submission(s): 53

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

Output

For each test case, print a positive integer or a string `Uncertain`.

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.

贪心策略 模拟一下就好了。把大的放在前面,记录一下最小的那个非0数字的位置然后把这个最小的非0的数字分割出来。与剩下的 相加就是最大的...

附上我愚蠢的代码

/* ***********************************************
Author        :guanjun
Created Time  :2016/7/17 18:53:46
File Name     :bc2nd_a.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
    int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
    }
};

bool cmp(char a,char b){
    return a>b;
}
char s[10000010];
int a[10000010];
vector<int>v;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    int t;

    cin>>t;
    while(t--){
        scanf("%s",s);
        v.clear();
        cle(a);
        int n=strlen(s);
        if(n==1)puts("Uncertain");
        else{
            sort(s,s+n);

                int num=0;
                int b,x;
                int mark=0;
                for(int i=0;i<n;i++){
                    a[i]=s[i]-‘0‘;
                    if(a[i]>0)num++;
                    if(a[i]>0&&!mark){
                        b=a[i];mark=1;
                        x=i;
                    }
                }
                if(num==1){
                    puts("Uncertain");continue;
                }
                //cout<<b<<endl;
                if(x!=0)a[0]+=b;
                else a[1]+=b;
                for(int i=0;i<n;i++){
                    if(i==x)continue;
                    if(a[i]>=10){
                        a[i]=a[i]%10;
                        if((i+1)!=x)a[i+1]++;
                        else a[i+2]++;
                    }
                    v.push_back(a[i]);
                }
                if(a[n]!=0)v.push_back(a[n]);
                for(int i=v.size()-1;i>=0;i--){
                    printf("%d",v[i]);
                }
                puts("");

        }
    }
    return 0;
}
时间: 2024-10-27 18:48:15

HDU 5718 Oracle的相关文章

hdu 5718 Oracle 高精度

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 beautifu

HDU 5718 Oracle(高精度)

Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u 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 admi

hdu 5718(Oracle)大数加法

曾经有一位国王,统治着一片未名之地.他膝下有三个女儿. 三个女儿中最年轻漂亮的当属Psyche.她的父亲不确定她未来的命运,于是他来到Delphi神庙求神谕. 神谕可以看作一个不含前导零的正整数n n n. 为了得到真正的预言,他可以将n n n的各个数位重新排列,并将其分成两个不含前导零的正整数. 请你帮助他求出这两个正整数最大的和.如果不存在这样的两个正整数,输出"Uncertain". 用getchar可以一个数字一个地读入,对于一个十进制数,最多就是10个数字,使用计数可以很方

Oracle11g温习-第一章:Oracle 体系架构

2013年4月27日 星期六 10:20 1.oracle 网络架构及应用环境 1. ORACLE 实例--包括内存结构与后台进程 2. ORACLE 数据库--物理操作系统文件的集合 3. 了解内存结构的组成 4. 了解后台进程的作用 5. 了解数据库的物理结构 6. 了解数据库的逻辑结构 2.oracle 体系结构   1)oracle server :database + instance 2)database:data file .control file . redolog file

扫描线三巨头 hdu1928&amp;&amp;hdu 1255 &amp;&amp; hdu 1542 [POJ 1151]

学习链接:http://blog.csdn.net/lwt36/article/details/48908031 学习扫描线主要学习的是一种扫描的思想,后期可以求解很多问题. 扫描线求矩形周长并 hdu 1928 Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4795    Accepted Submission(s):

HDU 3036 Escape 网格图多人逃生 网络流||二分匹配 建图技巧

前言 在编程过程中总结归纳出来的一种编程经验,从而形成的设计思想称为设计模式. 设计模式有23种.它适用于所有的编程语言. 常用的有创新型的设计模式:简单工厂.抽象工厂和单例模式:行为型的设计模式:模板设计模式.观察者模式和命令模式:结构性的设计模式:适配器设计模式.代理模式(静态和动态两种,典型的有在spring的AOP编程中使用)和装饰器设计模式. 正文 单例模式(singleton) 保证一个类在内存中只能创建一个实例. 1.实现步骤: 1)将构造器私有化,即使用private修饰构造器

【HDU 5721】Palace(平面最近点对)

[HDU 5721]Palace(平面最近点对) Palace Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 404    Accepted Submission(s): 104 Problem Description The last trial Venus imposes on Psyche is a quest to the

oracle安装故障:完美解决xhost +报错: unable to open display “”

oracle安装 先切换到root用户,执行xhost + 然后再切换到oracle用户,执行export DISPLAY=:0.0 出现乱码执行export LANG=US_en 在这里给大家介绍下两种情况的常见问题: 一种是本地运行的命令,另一种则是远程ssh命令安装. DISPLAY科普 DISPLAY变量是用来设置将图形显示到何处.比如CENTOS,你用图形界面登录进去,DISPLAY自动设置为DISPLAY=:0.0表示显式到本地监视器,那么通过终端工具(例如:xshell)进去,运行

Sqlserver通过链接服务器访问Oracle的解决办法

转自http://blog.sina.com.cn/s/blog_614b6f210100t80r.html 一.创建sqlserver链接服务(sqlserver链接oracle)  首先sqlserver 链接oracle可以通过两个访问接口: “MSDAORA” 和“OraOLEDB.Oracle” 1.“MSDAORA”访问接口是由Microsoft OLE DB Provider for Oracle提供的,这里建议不使用此接口进行链接.通过该访问接口建立的链接服务器在进行查询orac