CodeForce 570C Replacement (暴力)
来源:互联网 发布:首席体验官 知乎 编辑:程序博客网 时间:2024/05/21 01:51
http://codeforces.com/problemset/problem/570/C
题意:给一个字符串,然后两个连续的“.”可以变化一次,然后进行m次操作,问每次操作后可以进行如上的变换多少次。
这真的是一道很水的暴力题,但是我开始的做法真的是变态暴力,后来仔细想想之后的每次操作都可以由上一步的答案稍加推测得来。
设原来的字符串为S,进行操作的位置为pos,操作字符为op;
- 如果原来的 s[pos] 和 op相同,那么结果不变
- 如果二者不同,要把s[pos]换成op,那么讨论s[pos-1]和s[pos+1]的情况
具体的做法看代码。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;char s[300100];int main(){ int n,m; while(~scanf("%d %d",&n,&m)) { memset(s,0,sizeof(s)); for(int i=1;i<=n;i++) scanf(" %c",&s[i]); int cnt=0; int ans=0; for(int i=1;i<n;i++) { if(s[i]=='.'&&s[i+1]=='.') ans++; } while(m--) { int pos; char op; scanf("%d %c",&pos,&op); if(s[pos]=='.' && op!='.') { if(pos>=1&&s[pos+1]=='.') ans--; if(pos<=n&&s[pos-1]=='.') ans--; } else if(op=='.'&& s[pos]!='.') { if(pos>=1&&s[pos+1]=='.') ans++; if(pos<=n&&s[pos-1]=='.') ans++; } s[pos]=op; printf("%d\n",ans); } } return 0;}
我现在已经水的一无四处了,还是不能太浪…Orz。
0 0
- CodeForce 570C Replacement (暴力)
- Codeforces 570C Replacement 暴力
- CodeForce 463C Gargari and Bishops(贪心+暴力)
- codeforces 570-C. Replacement(预处理+规律)
- Codeforces 570C Replacement
- CodeForces-570C Replacement
- CF 570C Replacement
- Codeforces 570C Replacement
- CodeForces 570C Replacement 统计
- Codeorces 570C Replacement【思维】
- C. Replacement
- codeforce-243C:Colorado Potato Beetle(BFS+离散化+暴力)
- CodeForces 570C Replacement 线段树
- CodeForce 492C(贪心)
- Codeforce 552D Vanya and Triangles(暴力枚举)
- codeforce 723d Lakes in Berland(暴力DFS)
- Codeforces Round #316 (Div. 2)570C Replacement(脑洞)
- 570C. Replacement Codeforces Round #316 (Div. 2)
- 从Java到Groovy——Differences with Java
- 我参与的一个项目的继续总结:经验篇
- CentOS7安装Oracle_jdk7
- hdu2045不容易系列之(3)—— LELE的RPG难题
- 快速入门lua脚本语言
- CodeForce 570C Replacement (暴力)
- 编译PHP的正解
- JavaBean网页电子时钟
- MFC打包程序(一)
- 《金字塔原理》书评 - 伟大的方法论,但不是一本好书
- Ubuntu无线网速奇慢的问题
- Unity热更新专题(二)Lua编程语言
- 紫影龙的编程日记 —— 算法与数据结构
- SPOJ 375 Query on a tree(树链剖分)