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 ...
随机推荐
- sourceforge文件下载过慢
sourceforge文件下载过慢,可以用下面网址镜像下载, http://sourceforge.mirrorservice.org 按搜索到的项目的英文字母依次查询,如http://sourcef ...
- JVM 最多支持多少个线程?
阅读本文大概需要 2.8 分钟. 原文:www.jb51.net/article/49087.htm McGovernTheory 在 StackOverflow 提了这样一个问题: Java 虚拟机 ...
- .NET Core 代码安装服务启动
最近做了一些.NET Core的程序,有在Windows下运行的 有在CentOS 下运行的,Windows下运行的还好,对Windows下还算比较熟悉了,但CentOS 下 每次都是找笔记支持命令 ...
- 初识RSA
基础知识:http://www.guideep.com/read?guide=5676830073815040# python实现:https://blog.csdn.net/bian_h_f6127 ...
- ChIP-seq | ATAC-seq | 数据分析流程
思来想去,还是觉得ENCODE的流程靠谱,所以又花了快一周来调试,终于排除万难,跑成功了.[2019年12月08日] 以下是ATAC生成的结果目录: call-align call-call_peak ...
- pg数据库中时间查询的方式
方法一:select * from user_info where create_date>= '2015-07-01' and create_date < '2015-08-15'; 方 ...
- Mac下GoogleChromeHelper占用内存过高 的一个排查过程记录
测试需要在Mac上装了个虚拟机,结果忘记限制资源了,直接崩溃重启过一次. 后面限制了一下资源,发现内存占用率还是特别高,其中最高的居然是Chrome相关的一个东西.这让我8G内存该如何是好. 于是查了 ...
- C++ list运用实例
C++ list运用实例 #include <list> #include <iostream> #include <algorithm> #include < ...
- Visual Assist之Hashtags功能简介
Visual Assist是一款非常好的Visual Studio下开发的插件,网上已经有很多关于它的配置以及相关介绍,本文不再赘述.本文将注重介绍它的Hashtags功能. 本文主要内容来自于官网介 ...
- GWAS+自然选择:62个样本的GWAS分析,没信号,如何巧妙的发文章
欢迎来到"bio生物信息"的世界 6天前,BMC Genomics 推了一篇文献"Population history and genetic adaptation of ...