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 ...
随机推荐
- OpenFOAM——前台阶
本算例来自<ANSYS Fluid Dynamics Verification Manual>中的VMFL037:Turbulent Flow Over a Forward Facing ...
- python之turtle使用:画一颗美美哒的树
关于工具介绍这里小生就不赘述了,这里附上个人觉得最详细的文档地址:https://docs.python.org/zh-cn/3/library/turtle.html?highlight=turtl ...
- 阿里P8架构师深度概述分布式架构
简介 作为一名架构师,我们要专业,要能看懂代码,及时光着臂膀去机房,也能独挡一面!及时同事搞不定问题,或者撂挑子,你也能给老大一个坚定的眼神:不怕,有我在!还能在会议室上滔滔不绝,如若无人,让不懂技术 ...
- Linux 删除文件未释放空间问题处理,下清空或删除大文件
linux里的文件被删除后,空间没有被释放是因为在Linux系统中,通过rm或者文件管理器删除文件将会从文件系统的目录结构上解除链接(unlink).然而如果文件是被打开的(有一个进程正在使用),那么 ...
- 如何查看电脑的GPU信息
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_33690342/article/ ...
- ubuntu下Vim安装失败
sudo apt-get install vim Reading package lists... Done Building dependency tree Reading state inform ...
- 【Swoole】计一次swoole_server配合laravel5启动报错:Address already in use[98]
[2019-11-11 11:42:25 @21371.0] WARNING swSocket_bind(:434): bind(0.0.0.0:9501) failed, Error: Addre ...
- 华为云ARM64服务器试用
公司同事弄了个华为云的ARM64服务器,让我帮忙部署我们的服务,所以先试用了一下. 总体感觉还行,使用的CentOS系统,yum也能用,epel源也可以用.但是SCL软件集用不了. uname -a ...
- odoo开发笔记 -- odoo权限管理
odoo框架 整体权限可以分为4个级别: (1) 菜单级别: 不属于指定菜单所包含组的用,看不到相应菜单.不安全,只是隐藏菜单,若用户知道菜单ID,仍然可以通过指定URL访问(2) 对象级别: 对某个 ...
- flutter 高德地图选择位置信息返回
添加依赖:(注意,作者一直更新维护,请以最新的版本添加) amap_map_fluttify: ^ amap_search_fluttify: ^ 代码实现: import 'package:amap ...