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)的更多相关文章

  1. 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] ...

  2. 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)

    题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...

  8. Codeforces Round #581(Div. 2)

    Codeforces Round #581(Div. 2) CF 1204 A. BowWow and the Timetable 题解:发现,$4$的幂次的二进制就是一个$1$后面跟偶数个$0$. ...

  9. 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 ...

随机推荐

  1. [linux][c++]linux c++ 通过xcb库获取屏幕大小

    linux c++ 通过xcb库获取屏幕大小 #include <stdio.h> #include <xcb/xcb.h> /** clang++ main.cpp -o m ...

  2. jquery实现select数据回显

    [html] view plain copy     <select class="div_select_re" id="edit_technicalGrade&q ...

  3. Java String.split()函数分隔回车注意事项

    作者:Sun1956 原文:https://blog.csdn.net/sun1956/article/details/45096117 --------------------- 我们在Java中如 ...

  4. C#实体类对应SQL数据库的自增长ID怎么设置?

    /// <summary> /// 自增长ID /// </summary> [DatabaseGenerated(DatabaseGeneratedOption.Identi ...

  5. Xamarin.FormsShell基础教程(5)Shell项目内容新建页面

    Xamarin.FormsShell基础教程(5)Shell项目内容新建页面 轻拍内容列表页面中的Add按钮后,进入内容新建页面,如图1.4和图1.5所示.在该页面中,用户可以设置新建内容的标题和具体 ...

  6. TortoiseSVN is locked in another working copy

    TortoiseSVN提交报错 TortoiseSVN is locked in another working copy原因:可能是因为打开了多个commit会话,然后又去修改了提交文件的内容,导致 ...

  7. 解决SQL Server 阻止了对组件Ad Hoc Distributed Queries访问的方法

    来源:http://www.htmer.com/article/922.htm 今天单位一ASP.NET网站,里面有个功能是导出数据,发现一导出就报错,报错内容是:SQL  Server 阻止了对组件 ...

  8. Win64 驱动内核编程-33.枚举与删除对象回调

    转载:http://www.voidcn.com/article/p-wulgeluy-bao.html 枚举与删除对象回调 对象回调存储在对应对象结构体里,简单来说,就是存储在 ObjectType ...

  9. Difference Between Accuracy and Precision

    What Is the Difference Between Accuracy and Precision? https://www.thoughtco.com/difference-between- ...

  10. Docker管理控制相关资源

    一台宿主机可以放多个容器,默认的情况下,Docker 没有对容器进行硬件资源的限制,当容器负载过高时会尽可能的占用宿主机资源,所以有时候我们需要对容器的资源使用设置一个上限,这里就需要管理 Docke ...