题意:
给你一个字符串,和一些替换某个位置的字符的操作,问你每次替换完某个字符后,消除所以点的步数是多少。
思路:
找规律。列举出一些点后,发现每次要求的答案=总的小点数-小点的区间个数。
然后就是对于替换的字符是.或者字母,替换的位置是中间还是两边,分情况讨论下。
#include<cstdio>
const int MAX=300005;
int n,m;
char s[MAX];
int main(){
scanf("%d%d",&n,&m);
scanf("%s",s+1);
int num1=0,num2=0;
bool flag=false;
for(int i=1;i<=n;i++){
if(s[i]=='.') num1++;
if(s[i]=='.'&&flag==false){
num2++;
flag=true;
}
if(s[i]!='.') flag=false;
}
int x;
char c[10];
while(m--){
scanf("%d%s",&x,c);
if(s[x]=='.'){
if(c[0]!='.'){
num1--;
if(x==1){
if(s[x+1]!='.') num2--;
}
else if(x==n){
if(s[x-1]!='.') num2--;
}
else{
if(s[x-1]=='.'&&s[x+1]=='.') num2++;
else if(s[x-1]!='.'&&s[x+1]!='.') num2--;
}
}
}
else{
if(c[0]=='.'){
num1++;
if(x==1){
if(s[x+1]!='.') num2++;
}
else if(x==n){
if(s[x-1]!='.') num2++;
}
else{
if(s[x-1]=='.'&&s[x+1]=='.') num2--;
else if(s[x-1]!='.'&&s[x+1]!='.') num2++;
}
}
}
s[x]=c[0];
printf("%d\n",num1-num2);
}
return 0;
}