CF1702B Polycarp Writes a Srting from Memory 题解
给定一个字符串,每天可以记忆三个字符,求书写出整个字符串的天数。
每次确定要记忆的三个字母,并向后寻找,若有非三个字母其中一个,则重新开启一天记忆三个字母。
#include<cstdio>
#include<iostream>
using namespace std;
int t;
string s;
int main(){
scanf("%d",&t);
while(t--){
cin>>s;
char a='0',b='0',c='0';//记忆三个字母
bool f1=false,f2=false,f3=false;//三个字母是否有值
int ans=1;//刚开始天数为1
for(int i=0;i<s.size();i++){
if(f1&&f2&&f3){
if(s[i]!=a&&s[i]!=b&&s[i]!=c){//如果是未记忆,重新开启一轮
f1=false;
f2=false;
f3=false;//恢复状态
ans++;//天数+1
a='0';
b='0';
c='0';
}
else continue;
}
if(!f1&&s[i]!=b&&s[i]!=c){//寻找需记忆的三个字母
a=s[i];
f1=true;
continue;
}
if(!f2&&s[i]!=a&&s[i]!=c){
b=s[i];
f2=true;
continue;
}
if(!f3&&s[i]!=a&&s[i]!=b){
c=s[i];
f3=true;
continue;
}
}
printf("%d\n",ans);
}
return 0;
}
CF1702B Polycarp Writes a Srting from Memory 题解的更多相关文章
- Codeforces Round #479 (Div. 3)题解
CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...
- 工作于内存和文件之间的页缓存, Page Cache, the Affair Between Memory and Files
原文作者:Gustavo Duarte 原文地址:http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait ...
- Page Cache, the Affair Between Memory and Files
Previously we looked at how the kernel manages virtual memory for a user process, but files and I/O ...
- PatentTips - Reducing Write Amplification in a Flash Memory
BACKGROUND OF THE INVENTION Conventional NAND Flash memories move data in the background to write ov ...
- 【并行计算-CUDA开发】CUDA bank conflict in shared memory
http://hi.baidu.com/pengkuny/item/c8070b388d75d481b611db7a 以前以为 shared memory 是一个万能的 L1 cache,速度很快,只 ...
- 【Codeforces】CF Round #592 (Div. 2) - 题解
Problem - A Tomorrow is a difficult day for Polycarp: he has to attend \(a\) lectures and \(b\) prac ...
- Codeforces 997D(STL+排序)
D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces Round #479 (Div. 3)
手速场2333,这群人贼牛逼!手速贼快! A. Wrong Subtraction time limit per test 1 second memory limit per test 256 m ...
- Fedora 24中的日志管理
Introduction Log files are files that contain messages about the system, including the kernel, servi ...
随机推荐
- 评价管理后台PC端
1.css动画效果 --2020.12.26 2.remove() --2020.12.28 3.执行顺序 --2020.12.30 4.联动 --2021.01.06 5.奥利给~ --202 ...
- 蓝桥杯Web:【功能实现】菜单树检索
[功能实现]菜单树检索 背景介绍 实际工作中很多前端攻城狮都会遇到这样一个需求:在多级菜单树中模糊搜索匹配的菜单项,并显示出来. 本题需要在已提供的基础项目中使用 Vue.js 知识,实现对已提供的二 ...
- Android 12(S) 图像显示系统 - SurfaceFlinger GPU合成/CLIENT合成方式 - 随笔1
必读: Android 12(S) 图像显示系统 - 开篇 一.前言 SurfaceFlinger中的图层选择GPU合成(CLIENT合成方式)时,会把待合成的图层Layers通过renderengi ...
- scanf需要多输入一行是什么问题
有大佬知道用scanf输入,执行程序要多输入一行才能运行一般是什么问题呢 scanf的问题,其中多了\n. scanf如果加入\n,会导致需要多输入一次数据. 错误实例:
- 基于.NetCore开发博客项目 StarBlog - (6) 页面开发之博客文章列表
系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...
- Seata源码分析(一). AT模式底层实现
目录 GlobalTransactionScanner 继承AbstractAutoProxyCreator 实现InitializingBean接口 写在最后 以AT为例,我们使用Seata时只需要 ...
- ASP.NET MVC 处理管线模型
MVC管道整体处理模型 1.在ASP.NET MVC处理管线中的第一站就是路由模块.当请求到达路由模块后,MVC框架就会根据Route Table中配置的路由模板来匹配当前请求以获得对应的contro ...
- 人体调优不完全指南「GitHub 热点速览 v.22.22」
本周特推又是一个人体调优项目,换而言之就是如何健康生活,同之前的 HowToLiveLonger研究全因死亡率不同,这个项目更容易在生活中实践,比如,早起晒太阳这么一件"小事"便有 ...
- 【原创】项目五w1r3s.v1.0
实战记录 1.nmap信息枚举 1)C段扫描 nmap -sP 192.168.186.0/24 2)扫描全端口信息 nmap -p- 192.168.186.143 3)扫描版本信息 nmap -p ...
- 优先队列STL
引入 优先队列是一种特殊的队列,它的功能是--自动排序. 基本操作: q.size(); //返回q里元素个数 q.empty(); //返回q是否为空,空则返回1,否则返回0 q.push(k); ...