Oracle

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

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.

 
Source
 
题意:将一个大数分解成两个数字,要求两个数字是没有前导0的正整数,然后问相加的结果的最大值.
题解:先对输入的串从大到小排个序,如果输入的串长度为1或者 除了第一位全部都是 0,那么无解,其余的情况将第一个大于0的数取出来,然后剩下的数组成一个串相加即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define N 10000005
char str[N];
char result[N];
char b[];
int cmp(char a,char b)
{
return a>b;
}
void reverse( char *s ) /*将字符串逆置*/
{
int length;
int i = ;
char temp;
length = strlen( s );
while( i < length - i - )
{
temp = s[i];
s[i] = s[length - i - ];
s[length - i - ] = temp;
i++;
}
}
void AddBigNum( char* s1, char* s2, char* result )
{
int len1 = strlen( s1 );
int len2 = strlen( s2 );
int acc = , temp, i; /*acc为进位标记*/
if( s1 == NULL || s2 == NULL || result == NULL )
{
return;
}
reverse( s1 );
reverse( s2 );
for( i = ; i < len1 && i < len2; i++ )
{
temp = s1[i] - '' + s2[i] - '' + acc; /*计算每位的实际和*/
result[i] = temp % + ''; /*通过求余数来确定每位的最终值*/
if( temp >= ) /*通过这个if..else..条件来判断是否有进位,并设置进位值*/
acc = ;
else
acc = ;
}
if( i < len1 ) /*两个加数位数不同*/
{
for( ; i < len1; i++ )
{
temp = s1[i] - '' + acc; /*依旧要考虑进位,比如9999 + 1的情况*/
result[i] = temp % + '';
if( temp >= )
acc = ;
else
acc = ;
}
}
if( i < len2 )
{
for( ; i < len2; i++ )
{
temp = s2[i] - '' + acc;
result[i] = temp % + '';
if( temp >= )
acc = ;
else
acc = ;
}
}
if( acc == ) /*考虑如:123 + 911 = 1034的情况,如果不增加这个条件会得到结果为034,进位被舍弃*/
result[i++] = '';
result[i] = '\0';
reverse( result );
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%s",str);
int len = strlen(str);
sort(str,str+len,cmp);
if(len==)
{
printf("Uncertain\n");
}
else
{
bool flag = true;
int ans = ;
for(int i=len-; i>=; i--)
{
if(str[i]!='')
{
ans = i;
break;
}
}
if(ans==)
{
printf("Uncertain\n");
continue;
}
b[] = str[ans];
int id = ;
for(int i=; i<len; i++)
{
if(i==ans) continue;
str[id++] = str[i];
}
str[id]='\0';
AddBigNum(str,b,result);
printf("%s\n",result);
}
}
return ;
}

Arrange

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

Problem Description
Accidentally, Cupid, god of desire has hurt himself with his own dart and fallen in love with Psyche.

This has drawn the fury of his mother, Venus. The goddess then throws before Psyche a great mass of mixed crops.

There are n heaps of crops in total, numbered from 1 to n.

Psyche needs to arrange them in a certain order, assume crops on the i-th position is Ai.

She is given some information about the final order of the crops:

1. the minimum value of A1,A2,...,Ai is Bi.

2. the maximum value of A1,A2,...,Ai is Ci.

She wants to know the number of valid permutations. As this number can be large, output it modulo 998244353.

Note that if there is no valid permutation, the answer is 0.

 
Input
The first line of input contains an integer T (1≤T≤15), which denotes the number of testcases.

For each test case, the first line of input contains single integer n (1≤n≤105).

The second line contains n integers, the i-th integer denotes Bi (1≤Bi≤n).

The third line contains n integers, the i-th integer denotes Ci (1≤Ci≤n).

 
Output
For each testcase, print the number of valid permutations modulo 998244353.
 
Sample Input
2
3
2 1 1
2 2 3
5
5 4 3 2 1
1 2 3 4 5
 
Sample Output
1
0

Hint

In the first example, there is only one valid permutation (2,1,3) .

In the second example, it is obvious that there is no valid permutation.

 
Source
 
题意:在由 1 - n 中的数字组成的n个谷堆,假设前 i 个谷堆的最大值是C[i],最小值是B[i],现在知道这n堆谷堆前所有前缀的最大值和最小值,问这些谷堆总共有多少种组成方式??
题解:递推,排除掉5种不可能的情况,1.b[i]>b[i-1] 2,c[i]<c[i-1] 3,b[i]>c[i] 4.c[1]!=b[1] 5.b[i],c[i] < 1 || > n ,然后递推,如果当前产生的新的 b[i]或者 c[i] 那么dp[i] = dp[i-1] ,如果当前 b[i-1] = b[i] && c[i-1] = c[i] ,那么我们可以在 [b[i],c[i]]中任选一个数,但是由于谷堆是互不相同的,所以每次我们的选项都会变少,弄个计数器计算一下当前已经选了多少种,减掉之后答案即为 dp[i] = dp[i-1]*(c[i]-b[i]+1-num)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const long long mod = ;
const int N = ;
int b[N],c[N];
long long dp[N];
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n;
scanf("%d",&n);
int MIN = ;
int MAX = -;
bool flag = true;
for(int i=;i<=n;i++){
scanf("%d",&b[i]);
if(b[i]<||b[i]>n) flag = false;
if(b[i]>MIN) flag = false;
MIN = min(MIN,b[i]);
}
for(int i=;i<=n;i++){
scanf("%d",&c[i]);
if(c[i]<MAX) flag = false;
if(c[i]<||c[i]>n) flag = false;
MAX = max(MAX,c[i]);
if(c[i]<b[i]) flag = false;
}
if(!flag||c[]!=b[]) printf("0\n");
else{
memset(dp,,sizeof(dp));
dp[] = ;
int num = ;
for(int i=;i<=n;i++){
if(c[i]==c[i-]&&b[i-]==b[i]) {
dp[i] = dp[i-]*(c[i]-b[i]-num+)%mod;
}
else if(b[i]<b[i-]&&c[i-]==c[i]||b[i]==b[i-]&&c[i-]<c[i]){
dp[i] = dp[i-];
}
num++;
}
printf("%I64d\n",dp[n]);
}
}
return ;
}

BestCoder 2nd Anniversary的前两题的更多相关文章

  1. BestCoder 2nd Anniversary

    A题 Oracle http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1001 大数相加: ...

  2. Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)

    感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以 ...

  3. 牛客 2020.10.20 TG 前两题

    T1 GCD 数学水题... 对于每个数,如果这个数有两个及以上的质因数的话,它所有除 \(1\) 之外的因数求 \(GCD\) 的值一定为 \(1\).那么判断是否是质数或质数的次方即可(质数除 \ ...

  4. hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...

  5. BestCoder 2nd Anniversary 1001 Oracle

    找到最小的非零数字拆开来相加. 高精度. #include <iostream> #include <cstdio> #include <cstring> #inc ...

  6. hihocoder 前两题思路

    1800 : 玩具设计师 二维前缀和的写法有很多,最常见的是s[x-1][y]+s[x][y-1]-s[x-1][y-1]+a[x][y]; 涉及二维矩阵求和,联想前缀和,求>=指定面积的最大耐 ...

  7. BestCoder 2nd Anniversary/HDU 5719 姿势

    Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...

  8. BestCoder 2nd Anniversary/HDU 5718 高精度 模拟

    Oracle Accepts: 599 Submissions: 2576 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/26 ...

  9. hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...

随机推荐

  1. Spring---BeanFactory与ApplicationContext简介

    BeanFactory概念 Spring通过一个配置文件描述bean和bean之间的依赖关系,然后利用java语言的反射功能实例化bean,并建立bean之间的依赖关系.Spring的IOC容器在完成 ...

  2. python 三目运算

    python中的三目运算: result = a if condition else b #当满足condition返回a否则返回b 三目运算可以使你的代码看起来简洁,且运算高效

  3. [译]8-spring bean的作用域

    在spring中使用<bean/>标签定义bean的时候,可以使用scope属性来定义bean的作用域.如果想要每次 从spring容器得到一个新创建的bean实例,可以指定scope=& ...

  4. VMware下Linux配置局域网和外网访问

    我想尝试的是利用本机的ip+port来访问虚拟机上的web服务器,因为这样的话,我就能够将我的web服务器部署成为一个能让外网访问的服务器了,首先说下我的环境: 主机:系统win7,ip地址172.1 ...

  5. VS调试时不捕捉Exception

    在方法上添加 [DebuggerHidden] 这样,发生错误的时候,VS就不会捕捉到这个错误,否则,会在错误的地方中断. [DebuggerHidden] public void DeleteAll ...

  6. Spring 学习笔记(六)—— AOP的简单理解

    系统中的业务可以分为核心关注点和横切关注点. 核心关注点时业务处理的主要流程,而横切关注点是与核心业务无关但更为通用的业务. 各个横切关注点离散地穿插于核心业务之中,导致系统地每一个模块都与这些业务具 ...

  7. 初识 HTML5(一)

    H5其实就是H4的一个增强版本,我们在利用H5进行网页的构造会更简便,标签语义更简洁明了.首先,我们要理解HTML4,它是HTML的标记+css2+JavaScript的一些基本应用,简言之,就是AP ...

  8. Windows7下打开特定的端口

    往往我们发布到IIS的网站多了,80的端口不能满足的情况下,我们就会想到设定其它端口来使用.当然还可以通过改变host文件来实现,这里就不细说了.回到端口,在windows7系统下怎么实现呢?下面将带 ...

  9. 基于eclipse+maven创建web工程

    Eclipse+Maven创建webapp项目<一> 1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显 ...

  10. easyUI layout

    layout是一个容器,它有5个区域:north(北丐),south(南帝),east(东邪),west(西毒),center(中神通),像不像金庸的天龙八部,中间区域的panel是必须的, 周边区域 ...