BestCoder 2nd Anniversary的前两题
Oracle
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 79 Accepted Submission(s): 41
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 <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
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.
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).
3
2 1 1
2 2 3
5
5 4 3 2 1
1 2 3 4 5
0
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.
#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的前两题的更多相关文章
- BestCoder 2nd Anniversary
A题 Oracle http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1001 大数相加: ...
- Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)
感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以 ...
- 牛客 2020.10.20 TG 前两题
T1 GCD 数学水题... 对于每个数,如果这个数有两个及以上的质因数的话,它所有除 \(1\) 之外的因数求 \(GCD\) 的值一定为 \(1\).那么判断是否是质数或质数的次方即可(质数除 \ ...
- hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...
- BestCoder 2nd Anniversary 1001 Oracle
找到最小的非零数字拆开来相加. 高精度. #include <iostream> #include <cstdio> #include <cstring> #inc ...
- hihocoder 前两题思路
1800 : 玩具设计师 二维前缀和的写法有很多,最常见的是s[x-1][y]+s[x][y-1]-s[x-1][y-1]+a[x][y]; 涉及二维矩阵求和,联想前缀和,求>=指定面积的最大耐 ...
- BestCoder 2nd Anniversary/HDU 5719 姿势
Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...
- BestCoder 2nd Anniversary/HDU 5718 高精度 模拟
Oracle Accepts: 599 Submissions: 2576 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/26 ...
- hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...
随机推荐
- cocos2d-x 3.0 导演,场景,层,精灵
导演(Director) 一款游戏好比一部电影,只是游戏具有更强的交互性,不过它们的基本原理是一致的.所以在Cocos2dx中把统筹游戏大局的类抽象为导演(Director),Director是整个c ...
- 路由vue-router进阶
目录 1. 导航守卫 1.1. 全局守卫 1.2. 全局解析守卫 1.3. 全局后置钩子 1.4. 路由独享的守卫 1.5. 组件内的守卫 1.6. 完整的导航解析流程 2. 路由元信息 3. 获取数 ...
- 大数据服务大比拼:AWS VS. AzureVS.谷歌
[TechTarget中国原创] 对于企业用户来说,大数据服务是一项较具吸引力的云服务.三大巨头AWS.Azure以及谷歌都在力争夺得头把交椅,但是最后到底是哪一家能够取得王座之战的胜利呢? 云市场正 ...
- linux下解压命令大全[转]
本文是复制大神的博文, 供自己参考. 原文出处:http://www.cnblogs.com/eoiioe/archive/2008/09/20/1294681.html .tar 解包:tar xv ...
- 抓包工具 - Fiddler - (一)
<转载于 miantest> Fiddler基础知识 Fiddler是强大的抓包工具,它的原理是以web代理服务器的形式进行工作的,使用的代理地址是:127.0.0.1,端口默认为8888 ...
- Box布局管理
创建wx.BoxSizer对象时可以指定布局方向: hbox = wx.BoxSizer(wx.HORIZONTAL) 设置为水平方向 hbox = wx.BoxSizer() 默认就是就是水平方向的 ...
- Entity Framework(四)--EF原理和状态管理
一.原理: 如何查看真正执行的SQL是怎样的? DbContext有一个Database属性,Database属性有一个Log属性,是Action委托类型其中的参数就是sql语句,每次EF执行sql语 ...
- (原)Unreal渲染模块 源码和实例分析说明
@author:白袍小道 说明 1.由于小道就三境武夫而已,而UE渲染部分不仅管理挺大,而且牵扯技术和内容驳杂,所以才有这篇梳理. 2.尽量会按书籍和资料,源码,小模块的调试和搬山(就是敲键盘)..等 ...
- OZ常见错误解决办法
执行成功 错误信息解决办法 libvirt.libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No ...
- 剑指offer-从尾到头打印链表03
class Solution: # 返回从尾部到头部的列表值序列,例如[1,2,3] def printListFromTailToHead(self, listNode): # write code ...