博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5718 Oracle
阅读量:4342 次
发布时间:2019-06-07

本文共 2827 字,大约阅读时间需要 9 分钟。

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        :guanjunCreated Time  :2016/7/17 18:53:46File Name     :bc2nd_a.cpp************************************************ */#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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
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
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
=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;}

 

转载于:https://www.cnblogs.com/pk28/p/5679758.html

你可能感兴趣的文章
Fedora14 mount出现错误时解决办法【亲测有效】
查看>>
实验四
查看>>
回顾冒泡排序
查看>>
Ajax
查看>>
006 numpy常用函数
查看>>
tensorflow学习笔记(二)
查看>>
HttpModule Url 重写
查看>>
关于CKEditor 4.0 过滤html标签
查看>>
java编程经典语录
查看>>
豆瓣小站维护:【代码review】数据结构与算法分析(C++) 1.3题
查看>>
Java虚拟机监控命令
查看>>
1. Hello World - WebService based on Spring
查看>>
IntelliJ IDEA设置统一编码utf-8
查看>>
…… are only available on JDK 1.5 and higher 错误(spring 的jdk版本检测在jdk 8下的修订)...
查看>>
分布式缓存小结
查看>>
uva 437 hdu 1069
查看>>
Leetcode 609: Find Duplicate File in System
查看>>
javascript 高级程序设计 重点
查看>>
python第二十八天,(元类,异常处理,)
查看>>
翰思博客
查看>>