CodeForces 570C Replacement 统计

原题:

题目大意: 对于连续有n个‘.’,我们的答案是n-1,就可以理解为点是空格,,其他是单词字符,在不改变单词的情况下,有多少空格可以删。也就是该有点的地方除了一个点还有多少个点。

我们只需要考虑修改后的元素和之前元素的不同,如果都为点或者字母,答案不变。 如果之前是点,两边都是点,现在改成字符,那么结果要减2,因为不管其他地方的,至少该位置的点不能被删去了,它后面的点因为它的存在也不能删去了。 枚举每一种情况,就得出了结果。

namespace std;typedef lint;const int N= 300005;char s[N];int main(){//freopen(“in.txt”,”r”,stdin);int n,m;while(scanf(“%d %d”,&n,&m)!=EOF){int cut=0;scanf(“%s”,s);for(int i=0; i<n;){if(s[i]==’.’){i++;while(s[i]==’.’){cut++;i++;}}elsei++;}//printf(“%d\n”,cut);char tt[10];int where;while(m–){scanf(“%d %s”,&where,tt);where–;if(where>0&&where<n-1){if(tt[0]==’.’&&s[where]!=’.’){if(s[where-1]==’.’&&s[where+1]==’.’) cut=cut+2;else if(s[where-1]==’.’&&s[where+1]!=’.’) cut++;else if(s[where-1]!=’.’&&s[where+1]==’.’) cut++;}else if(tt[0]!=’.’&&s[where]==’.’){if(s[where-1]==’.’&&s[where+1]==’.’) cut=cut-2;else if(s[where-1]==’.’&&s[where+1]!=’.’) cut–;else if(s[where-1]!=’.’&&s[where+1]==’.’) cut–;}}else if(where==0){if(tt[0]==’.’&&s[where]!=’.’){if(s[where+1]==’.’) cut++;}else if(tt[0]!=’.’&&s[where]==’.’){if(s[where+1]==’.’) cut–;}}else if(where==n-1){if(tt[0]==’.’&&s[where]!=’.’){if(s[where-1]==’.’) cut++;}else if(tt[0]!=’.’&&s[where]==’.’){if(s[where-1]==’.’) cut–;}}s[where]=tt[0];printf(“%d\n”,cut);}}return 0;}

只有不断找寻机会的人才会及时把握机会。

CodeForces 570C Replacement 统计

相关文章:

你感兴趣的文章:

标签云: