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 ...
随机推荐
- 下拉选择的blur和click事件冲突了
当写个下拉选择框时我们希望当input失去焦点时,下拉框消失,或者当选择下拉框中的内容的同时将内容填入input并且使下拉框消失. 这时候我们会想到blur和click,单独使用的时候是没有问题的,但 ...
- JS 将数字字符串数组转为 数字数组 (互换)
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; arr.map(String); //结果: ['1', '2', '3', '4', '5', '6', '7', '8 ...
- Windows(win2016、win2019、win10)在IIS下添加.NET Framework 3.5 NetFx3 失败 (状态为:0x800f0950)的解决办法
今天一个客户自己的电脑安装了一个windows server 2016 想装一个IIS,程序一个C+写的ERP,NET是必然,NET4.7可以安装了,但就是3.5,如何也装不上,错误(状态为:0x80 ...
- exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
1.情景展示 Java 报错信息如下: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 2.原因分析 首先,这是越界异常,但不是数组越 ...
- 灵活的MyBatis
一.前言 将数据存储到数据库是开发中很重要的一环.曾经有程序员说自己做过最牛逼的事情就是增删改查.确实我们做了很多页面,后太代码写了很多,可是最终都离不开数据库的增删改查.Java有一套自己的JPA标 ...
- 冰多多团队Beta阶段发布说明
Bingduoduo 语音Coding(Beta):项目Github地址 Beta版本新功能介绍 在beta阶段我们很好地将alpha阶段已经设计好的编辑器和shell整合了起来,推出了一个完整的ID ...
- php – 通过curl从url获取JSON数据
我试图通过curl连接从URL获取JSON数据.当我打开链接时:它显示{“version”:“N / A”,“success”:true,“status”:true}.现在,我希望获得以上内容. 到目 ...
- lightgbm GPU版本安装
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)https://study.163.com/course/introduction.htm?courseId=1005269003&u ...
- Zookeeper:Unable to read additional data from client sessionid 0x00, likely client has closed socket
异常信息: 2018-03-20 23:34:01,887 [myid:99] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerC ...
- Java12新特性 -- 默认生成类数据共享(CDS)归档文件
默认生成类数据共享(CDS)归档文件 同一个物理机/虚拟机上启动多个JVM时,如果每个虚拟机都单独装载自己需要的所有类,启动成本和内 存占用是比较高的.所以Java团队引入了类数据共享机制 (Clas ...