题意:

询问一共有有多少个CCPC,每个得1分,可以自己在任意位置添加字母,第i次添加需要耗费i-1分

思路:

既然每次添加需要耗分,添加第二个字母,相当于没有添加,所以只需要添加一次就好

先计算出原始字符串中的CCPC,在不破坏CCPC的前提下,添加字母即可

代码:

#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 2e5+10;
int flag[maxn];
char str[maxn];
int main() {
int t, n, ans, temp;
scanf("%d", &t);
while(t--) {
ans = temp = 0;
scanf("%d %s", &n, str+1);
for(int i = 1; i <= n; i++)
flag[i] = 0;
for(int i = 1; i <= n-3; i++) {
if(str[i]=='C' && str[i+1]=='C' && str[i+2]=='P' && str[i+3]=='C')
ans++, flag[i] = 1;
}
for(int i = 1; i <= n-2; i++) {
if(flag[i] || temp) continue;
if(str[i]=='C' && str[i+1]=='C' && str[i+2]=='C' && flag[i+1]==0) temp = 1;
else if(str[i]=='C' && str[i+1]=='P' && str[i+2]=='C' && flag[i-1]==0) temp = 1;
else if(str[i]=='C' && str[i+1]=='C' && str[i+2]=='P') temp = 1;
}
printf("%d\n", ans+temp);
}
return 0;
}

最新文章

  1. js获取css中的样式
  2. 浅谈webWorker
  3. ACM 杭电HDU 2084 数塔 [解题报告]
  4. UIViewContentMode各类型效果
  5. 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
  6. python从Microsoft Excel文件中导入数据
  7. ORACLE函数大全
  8. if分支的四种形式
  9. VHDL学习记录
  10. 分布式高性能消息处理中心HPMessageCenter
  11. jQuery---过滤选择器
  12. python摸爬滚打之day16----类的成员
  13. Elasticsearch基础知识要点QA
  14. windows 执行bat脚本
  15. WEB开发库收集
  16. MyEclipse同时配置多个tomcat
  17. (转)找回Git中丢失的Commit
  18. JVM gc介绍
  19. LNMP下安装memcache
  20. 2017-2018-1 20155207&amp;20155308《信息安全技术》实验四-木马及远程控制技术

热门文章

  1. android:模拟水波效果的自己定义View
  2. luogu1941 飞扬的小鸟
  3. 同一个站点下,兼容不同版本的JQuery
  4. POJ1743 Musical Theme 最长重复子串 利用后缀数组
  5. bzoj4031 [HEOI2015]小Z的房间——矩阵树定理
  6. FreeMarker:目录
  7. 如何彻底卸载Vs2015
  8. bzoj 1621: [Usaco2008 Open]Roads Around The Farm分岔路口【dfs】
  9. 04-Vue中的动画
  10. DataGridView 动态绑定 CheckBox