当前位置: 代码迷 >> 综合 >> bzoj4996: [Usaco2017 Feb]Why Did the Cow Cross the Road II
  详细解决方案

bzoj4996: [Usaco2017 Feb]Why Did the Cow Cross the Road II

热度:61   发布时间:2023-10-29 12:26:14.0

题意

英文题自己看。。

解法

TKJ说随便做,看代码就好了,水题

#include<cstdio>
#include<cstring>
const int N=100005;
int a[N];
int n,k,b;
int mymin (int x,int y){
   return x<y?x:y;}
int main()
{memset(a,0,sizeof(a));scanf("%d%d%d",&n,&k,&b);for (int u=1;u<=b;u++){int x;scanf("%d",&x);a[x]=1;}for (int u=1;u<=n;u++)  a[u]+=a[u-1];int ans=1<<30;for (int u=1;u<=n-k+1;u++)//左端点 ans=mymin(ans,a[u+k-1]-a[u-1]);printf("%d\n",ans);return 0;
}
  相关解决方案