2019牛客暑期多校训练营(第八场)G Gemstones(模拟)
时间:2019-08-17
本文章向大家介绍2019牛客暑期多校训练营(第八场)G Gemstones(模拟),主要包括2019牛客暑期多校训练营(第八场)G Gemstones(模拟)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
链接: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.
输入描述:
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
说明
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-9 string 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
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- React17新特性:启发式更新算法
- spring之通过FactoryBean配置Bean
- 谱聚类的python实现
- 基于TypeScript封装Axios笔记(三)
- hadoop伪分布式之启动HDFS并运行MR程序(WordCount)
- 细品Reids的HyperLogLog数据结构
- 布隆过滤器与缓存击穿
- spring之通过注解方式配置Bean(二)
- 【python-leetcode103-树的宽度遍历】二叉树的锯齿形层次遍历
- 图卷积网络(GCN)python实现
- hadoop伪分布式之配置yarn并运行MR程序(WordCount)
- 【python-leetcode637-树的宽度遍历】二叉树的层平均值
- graphSAGE的python实现
- 【python-leetcode111-树的宽度遍历】二叉树的最小深度
- 基于TypeScript封装Axios笔记(四)