50分求助,谢谢

P3662 [USACO17FEB] Why Did the Cow Cross the Road II S

```cpp #include<bits/stdc++.h> using namespace std; int n,k,b,a[1000000],ans=9999999,m=0,p=1; bool c[1000000]; int main(){ cin>>n>>k>>b; for(int i=1;i<=b;i++){ cin>>a[i]; } memset(c,1,sizeof(c)); for(int i=1;i<=n;i++){ c[a[i]]=0; } while(k<=n){ for(int i=p+0;i<=k;i++){ if(c[i]==0) m++; } if(m<ans) ans=m; k++; p++; m=0; } cout<<ans; return 0; } //暴力加O2搞定
by gengxinbujianduan @ 2023-07-12 17:09:39


|