bzoj 4996: [Usaco2017 Feb]Why Did the Cow Cross the Road II
2017-09-02 01:41
513 查看
bzoj没有题面....
链接是到洛谷的
→题目链接←
维护有多少坏掉的路灯的前缀和
然后对于每个sum[i]-sum[i-k]取max就好
代码:
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
int n,k,m;
int sum[100010];
bool f[100010];
int ans;
int main(){
scanf("%d%d%d",&n,&k,&m);
ans=m;
for(int i=0; i<m; i++){
int x;
scanf("%d",&x);
f[x]=true;
}
for(int i=1; i<=n; i++)sum[i]=sum[i-1]+f[i];
for(int i=k; i<=n; i++)ans=min(ans,sum[i]-sum[i-k]);
printf("%d\n",ans);
return 0;
}
bzoj没有题面....
链接是到洛谷的
链接是到洛谷的
→题目链接←
维护有多少坏掉的路灯的前缀和
然后对于每个sum[i]-sum[i-k]取max就好
代码:
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
int n,k,m;
int sum[100010];
bool f[100010];
int ans;
int main(){
scanf("%d%d%d",&n,&k,&m);
ans=m;
for(int i=0; i<m; i++){
int x;
scanf("%d",&x);
f[x]=true;
}
for(int i=1; i<=n; i++)sum[i]=sum[i-1]+f[i];
for(int i=k; i<=n; i++)ans=min(ans,sum[i]-sum[i-k]);
printf("%d\n",ans);
return 0;
}
bzoj没有题面....
链接是到洛谷的
相关文章推荐
- 【bzoj4990】[Usaco2017 Feb]Why Did the Cow Cross the Road II
- BZOJ4990&&BZOJ4993(Usaco2017 Feb)[Why Did the Cow Cross the Road II]--最长升
- bzoj 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- bzoj 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- BZOJ 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 树状数组优化LCS
- [BZOJ4993||4990] [Usaco2017 Feb]Why Did the Cow Cross the Road II(DP + 线段树)
- BZOJ 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II LCS
- bzoj 4995: [Usaco2017 Feb]Why Did the Cow Cross the Road
- Bzoj4989 [Usaco2017 Feb]Why Did the Cow Cross the Road
- 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 线段树维护dp
- bzoj 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road
- bzoj 4991: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- BZOJ 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road 逆序对
- [Usaco2017 Feb]Why Did the Cow Cross the Road II
- BZOJ 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road
- 【bzoj4992: [Usaco2017 Feb]Why Did the Cow Cross the Road】动规
- [BZOJ4989] [Usaco2017 Feb]Why Did the Cow Cross the Road(树状数组)
- bzoj 4997: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj4990 [Usaco2017 Feb]Why Did the Cow Cross the Road II(dp+树状数组)
- BZOJ 4991 [Usaco2017 Feb]Why Did the Cow Cross the Road III 树状数组套splay【未AC】