https://ac.nowcoder.com/acm/problem/235096
双指针,就按这个形式写了
#include <iostream> #include <map> #include <cstring> #include <algorithm> using namespace std ; const int N=1e6+10; #define int long long int n,a,b; int A ; char s[N]; signed main(){ int l,r; cin>>n>>a>>b; cin>>(s+1); n=strlen(s+1) ; int c1=0,c2=0,ans=0 ; l=1,r=1; while(r<=n){ if(s[r]=='0') c1++; else c2++; while(l<=r &&(c1>=a) && (c2>=b)){ ans+= n-r+1; if(s[l]=='0') c1--; else c2--; l++; } r++; } if(a+b==0) ans++; cout<<ans<<endl; }
标签:int,nowcoder,++,ans,c2,天气预报,include From: https://www.cnblogs.com/towboa/p/17232041.html