zoukankan      html  css  js  c++  java
  • 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 (1T10), which denotes the number of test cases.

    For each test case, the single line contains an integer n (1n<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;char s[10000010];
    int a[10000010];
    vector<int>v;
    int main()
    {
        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;
                }
                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;
    }
  • 相关阅读:
    8、【转载】python enhanced generator - coroutine
    7、【转载】python yield generator 详解
    7、利用SAX编写程序解析Yahoo的XML格式的天气预报,获取天气预报
    6、urllib.request.Request类
    5、urllib.request.urlopen()
    重载内核的一份代码的学习
    分析
    CVE-2014-0282
    IOS逆向【5】GDB调试helloworld
    IOS逆向【4】.ipa安装
  • 原文地址:https://www.cnblogs.com/pk28/p/5679758.html
Copyright © 2011-2022 走看看