A.一定是前半段白后半段黑,枚举分界点预处理前后缀和。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #define rep(i,l,r) for (int i=(l); i<=(r); i++)
 6 typedef long long ll;
 7 using namespace std;
 8 
 9 const int N=200010;
10 char s[N];
11 int n,ans,pre[N],suf[N];
12 
13 int main(){
14     freopen("a.in","r",stdin);
15     freopen("a.out","w",stdout);
16     scanf("%d%s",&n,s+1); ans=n+1;
17     rep(i,1,n) pre[i]=pre[i-1]+(s[i]=='#');
18     for (int i=n; i; i--) suf[i]=suf[i+1]+(s[i]=='.');
19     rep(i,0,n) ans=min(ans,pre[i]+suf[i+1]);
20     printf("%d\n",ans);
21     return 0;
22 }
A

相关文章:

  • 2022-01-26
  • 2021-07-12
  • 2021-12-30
  • 2018-10-30
  • 2022-02-06
  • 2021-08-04
  • 2021-08-19
  • 2021-12-21
猜你喜欢
  • 2021-11-23
  • 2021-10-04
  • 2021-08-25
  • 2021-06-12
  • 2021-11-09
  • 2021-07-12
相关资源
相似解决方案