链接:https://ac.nowcoder.com/acm/contest/888/G
来源:牛客网

题目描述

Gromah and LZR have entered the seventh level. There are a sequence of gemstones on the wall.
After some tries, Gromah discovers that one can take exactly three successive gemstones with the same types away from the gemstone sequence each time, after taking away three gemstones, the left two parts of origin sequence will be merged to one sequence in origin order automatically.
For example, as for "ATCCCTTG", we can take three 'C's away with two parts "AT", "TTG" left, then the two parts will be merged to "ATTTG", and we can take three 'T's next time.
The password of this level is the maximum possible times to take gemstones from origin sequence.

Please help them to determine the maximum times.

输入描述:

Only one line containing a string ss_{}s​, denoting the gemstone sequence, where the same letters are regarded as the same types.
1≤∣s∣≤1051 \le |s| \le 10^51≤∣s∣≤105
ss_{}s​ only contains uppercase letters.

输出描述:

Print a non-negative integer in a single line, denoting the maximum times.
示例1

输入

复制

ATCCCTTG

输出

复制

2

说明

One possible way is that ‘‘ATCCCTTG "  →  ‘‘ATTTG "  →‘‘AG "``ATCCCTTG\,"  \; \rightarrow \; ``ATTTG\," \; \rightarrow ``AG\,"‘‘ATCCCTTG"→‘‘ATTTG"→‘‘AG".
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;#define ll long long
#define eps 1e-9string s;
int sign[100000 + 8], num[100000 + 8];int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>s;int len = s.size();int id = 0;int ans = 0;memset(num, 0, sizeof(num));for(int i = 0; i < len; i++){if(!i){sign[id] = s[i];num[id]++;}else{if(s[i] == sign[id]){num[id]++;if(num[id] == 3){num[id] = 0;id--;ans++;}}else{sign[++id] = s[i];num[id]++;}}}cout << ans << '\n';return 0;
}

转载于:https://www.cnblogs.com/RootVount/p/11368600.html

2019牛客暑期多校训练营(第八场)G Gemstones(模拟)相关推荐

  1. 2019牛客暑期多校训练营(第八场) CDMA

    时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语言1048576K Special Judge, 64bit IO Format: %lld 题目描述   Gro ...

  2. 【2019牛客暑期多校训练营(第二场) - H】Second Large Rectangle(单调栈,全1子矩阵变形)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/H 来源:牛客网 题目描述 Given a N×MN \times MN×M binary matrix. ...

  3. 2019牛客暑期多校训练营(第一场)E-ABBA(dp)

    链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  4. 2019牛客暑期多校训练营(第一场)

    传送门 参考资料: [1]:官方题解(提取码:t050 ) [2]:标程(提取码:rvxr ) [3]:牛客题解汇总 A.Equivalent Prefixes(单调栈) •题意 定义两个数组 u,v ...

  5. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  6. 【2019牛客暑期多校训练营(第二场)- E】MAZE(线段树优化dp,dp转矩阵乘法,线段树维护矩阵乘法)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/E?&headNav=acm 来源:牛客网 Given a maze with N rows an ...

  7. 【2019牛客暑期多校训练营(第二场)- F】Partition problem(dfs,均摊时间优化)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/F 来源:牛客网 Given 2N people, you need to assign each of ...

  8. 【2019牛客暑期多校训练营(第二场) - D】Kth Minimum Clique(bfs,tricks)

    题干: 链接:https://ac.nowcoder.com/acm/contest/882/D 来源:牛客网 Given a vertex-weighted graph with N vertice ...

  9. 【2019牛客暑期多校训练营(第一场) - A】Equivalent Prefixes(单调栈,tricks)

    题干: 链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Two arrays u and v each with m distinct elem ...

  10. 【2019牛客暑期多校训练营(第一场) - H】XOR(线性基,期望的线性性)

    题干: 链接:https://ac.nowcoder.com/acm/contest/881/H 来源:牛客网 Bobo has a set A of n integers a1,a2,-,ana1, ...

最新文章

  1. python 高级使用实例_Python中的高级函数map/reduce使用实例
  2. pycharm中显示额外的“figure”窗口
  3. linux下转邮局服务器步骤,邮件不能丢
  4. 适合零基础学python的书籍_适合零基础学习Python的书籍
  5. [机器学习] --- 参数优化与模型选择
  6. TreeMap实现对中文的排序
  7. [git 基础] 生成patch 和 打patch 的实例
  8. “焖鸡”游戏中的排序问题
  9. ajax获取java session的值_jquery 怎么获取 ajax中的session值
  10. init.rc语法与解析
  11. java操作数据库,以页面显示学生信息为例
  12. Vue笔记:使用 axios 中 this 指向问题
  13. 3月22 关于CSS
  14. 虚拟机网络配置(配置动态ip和静态ip)
  15. 书评 《编码: 隐匿在计算机软硬件背后的语言》
  16. Cocos Creator性能优化-4-内存优化
  17. Java——面向对象(1)
  18. 我来对比一下阿里云服务器和腾讯云服务器的优劣和区别
  19. android仿支付宝弹窗,实现支付宝支付从底部弹窗效果
  20. python中 s == s[::-1]是什么意思?

热门文章

  1. 解密QQ非会员漫游聊天记录
  2. 目标检测与转自背景减除
  3. Visual Studio 2008在设计视图和代码视图切换的快捷键F7
  4. Android ListView侧滑item,仿QQ删除效果
  5. 数据库分离 附加 sqlserver
  6. GHOST内部错误 36000(internal error 36000)情况的解决办法
  7. [翻译 EF Core in Action 2.1] 设置一个图书销售网站的场景
  8. 更改一字段的全部字节的大小写
  9. Django开发社交类网站必备的10个第三方应用
  10. LayaBox IDE 安装后执行项目报错解决方案的一些记录