Codeforces Round #581 (Div. 2)
A:暴力。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;
const int N=;
int n;
char s[N];
int main(){
scanf("%s",s+); n=strlen(s+); bool flag=;
rep(i,,n) if (s[i]=='') flag=;
if (s[]==''){ puts(""); return ; }
if (flag) printf("%d",(n+)/); else printf("%d\n",n/);
return ;
}
A
B:一定是1,2,4,...,2^k。最小和最大分别让1和2^k最多即可。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;
int n,l,r;
int main(){
cin>>n>>l>>r;
ll s1=n-l+; rep(i,,l-) s1+=1ll<<i;
ll s2=(1ll<<(r-))*(n-r+); rep(i,,r-) s2+=1ll<<i;
cout<<s1<<' '<<s2<<endl;
return ;
}
B
C:先floyd求最短路,然后每次找到当前点至多往后多少个点可以保证p走的一直都是最短路,然后走到那个点去。由于p如果某时刻走的不是最短路了,那么之后走的一定也都不是最短路。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;
const int N=,M=,inf=1e8;
char s[N];
int n,m,tot,f[N][N],p[M],q[M];
int main(){
scanf("%d",&n);
rep(i,,n) rep(j,,n) f[i][j]=inf;
rep(i,,n) f[i][i]=;
rep(i,,n){
scanf("%s",s+);
rep(j,,n) if (s[j]=='') f[i][j]=;
}
rep(k,,n) rep(i,,n) rep(j,,n) f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
scanf("%d",&m);
rep(i,,m) scanf("%d",&p[i]);
for (int i=,j; i<m; i=j){
q[++tot]=p[i];
rep(k,i+,m) if (f[p[i]][p[k]]==k-i) j=k; else break;
}
printf("%d\n",tot+);
rep(i,,tot) printf("%d ",q[i]); printf("%d\n",p[m]);
return ;
}
C
D1/D2:首先0不会变成1,然后考虑1变成0的必要条件并证明它是充分的。1能变成0,当且仅当存在一个以这个位置开头的子序列,满足它是这个位置到n的LIS。于是边倒着DP做LIS边判断每个1是否可以变成0即可。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;
const int N=;
char s[N],s2[N];
int n,sm,ans[N],f[N][];
int main(){
scanf("%s",s+); n=strlen(s+);
rep(i,,n) s2[i]=s[i];
for (int i=n; i; i--){
if (s[i]=='') f[i][]=max(f[i+][],f[i+][])+,f[i][]=f[i+][],sm++;
else f[i][]=f[i+][]+,f[i][]=f[i+][];
ans[i]=max(f[i][],f[i][])-sm;
}
for (int i=n; i; i--) if (ans[i]!=ans[i+]) s2[i]='';
rep(i,,n) putchar(s2[i]);
return ;
}
D
E:考虑求F[i]表示最大前缀和不小于i的数列个数,最后差分一下即可求出期望。先给结论:F[i]=C(n+m,n-i)。归纳证明,若数列最后一个数是-1,则前n+m-1个数的最大前缀和一定是i,这部分的贡献是C(n+m-1,n-i)。若是1,由于不能保证这个1一定在最大前缀和里,于是前n+m-1个数的最大前缀和仍然是i,这部分的贡献是C(n+m-1,n-i-1)。于是F[i]=C(n+m-1,n-i)+C(n+m-1,n-i-1)=C(n+m,n-i)。
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;
const int N=,mod=;
int n,m,ans,x,y,C[N][N];
int main(){
scanf("%d%d",&n,&m); C[][]=;
rep(i,,n+m){ C[i][]=; rep(j,,i) C[i][j]=(C[i-][j-]+C[i-][j])%mod; }
for (int i=n; i && i>=n-m; i--) x=(C[n+m][n-i]-y+mod)%mod,ans=(ans+1ll*x*i)%mod,y=(y+x)%mod;
printf("%d\n",ans);
return ;
}
E
Codeforces Round #581 (Div. 2)的更多相关文章
- Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学
Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学 [Problem Description] ...
- 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)
题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...
- Codeforces Round #581 (Div. 2) C. Anna, Svyatoslav and Maps (Floyd 算法,最短路)
C. Anna, Svyatoslav and Maps time limit per test2 seconds memory limit per test256 megabytes inputst ...
- D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)
D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...
- Codeforces Round #581 (Div. 2) B. Mislove Has Lost an Array (贪心)
B. Mislove Has Lost an Array time limit per test1 second memory limit per test256 megabytes inputsta ...
- Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)
A. BowWow and the Timetable time limit per test1 second memory limit per test256 megabytes inputstan ...
- Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...
- Codeforces Round #581(Div. 2)
Codeforces Round #581(Div. 2) CF 1204 A. BowWow and the Timetable 题解:发现,$4$的幂次的二进制就是一个$1$后面跟偶数个$0$. ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- luogu P1447 [NOI2010]能量采集 欧拉反演
题面 题目要我们求的东西可以化为: \[\sum_{i=1}^{n}\sum_{j=1}^{m}2*gcd(i,j)-1\] \[-nm+2\sum_{i=1}^{n}\sum_{j=1}^{m}gc ...
- 一种SpaceClaim抽取流道的方法——利用缺失的面功能
针对不干净的几何,内部存在诸多碎面小缝隙,采用此方法可能会有较好的效果,不过需要耐心. 测试几何需要SpaceClaim19.0以上软件可以打开,下载链接: https://pan.baidu.com ...
- oracle 如何判断字符串中是否包含中文?超级简单!
1.情景展示 如何快速的判断出指定字符串中是否包含中文呢? 2.解决方案 通过length()和lengthb()函数的比对结果进行判断. lengthb(string)计算string所占的字节 ...
- 2018ECNA Difference[时空复杂度]
目录 题干 代码和解释 题干 代码和解释 本题给出一个数列的第一个数A(1),要求找出m第一次出现(直接出现在数列中或是数列中某两项的差的绝对值)在这个数列的第几步中.数列递推公式:A(n+1)=A( ...
- jdk 6-13最有价值新特性总结
355: Text Blocks (Preview) JDK 13的特性.简化了大段文本的换行,例如sql或xml段. Shenandoah GC. jdk 12作为实验特性引入. JEP330-启动 ...
- ES6 - 对象扩展(增强字面量)
/** * 对象的扩展 * * 增强对象字面量 * * 解决问题:缩减代码 */ { /** * 1.属性简表示法 * 变量foo直接写在大括号里面.这时,属性名就是变量名, 属性值就是变量值 */ ...
- MQTT研究之EMQ:【CoAP协议的ECC证书研究】
今天研究的内容,是CoAP这个协议在EMQ消息队列的支持,CoAP是一个受限资源的协议,基于UDP实现的多用于物联网环境的通信协议.相关介绍不多说,可以看RFC. CoAP协议下,基于DTLS通信,同 ...
- java读取IFC文件
The IFC JAVA Toolbox can read IFC STEP files and IFCZIP files from any data source that implementsja ...
- 锐捷交换机如何配置远程管理地址(telnet)
基本命令如下: hostname(config)#username admin password 123456 ------>telnet 登录账号为admin密码为123456 hostna ...
- 自定义程序启动脚本加入到supervisord下管理
ubuntu14.04 系统,直接通过apt-get安装即可 apt-get install supervisord 官网:http://www.supervisord.org/ 主配置文件 这个配置 ...