Codeforces801A Vicious Keyboard 2017-04-19 00:16 241人阅读 评论(0) 收藏
2 seconds
256 megabytes
standard input
standard output
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string s with only these two letters. He really likes it when the string "VK"
appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK"
can appear as a substring (i. e. a letter "K" right after a letter "V")
in the resulting string.
The first line will contain a string s consisting only of uppercase English letters "V"
and "K" with length not less than 1 and
not greater than 100.
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
VK
1
VV
1
V
0
VKKKKKKKKKVVVVVVVVVK
3
KVKV
1
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K".
This will give us the string "VK". This has one occurrence of the string "VK"
as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V".
This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK"
as a substring. We can check no other moves can give us strictly more occurrences.
————————————————————————————————————
题目的意思是给出一个只含VK的字符串,你可以把其中一个换成另一个,问最多有几个VK
思路先跑一边记录有几个VK并标记,在搜一遍有没有相邻的没被标记过的可以构成VK的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue> using namespace std; int main()
{
char s[105];
int a[105];
while(~scanf("%s",s))
{
memset(a,0,sizeof a);
int k=strlen(s);
int ans=0;
for(int i=0;i<k-1;i++)
{
if(s[i]=='V'&&s[i+1]=='K')
{
a[i]=a[i+1]=1;
ans++;
i++;
}
}
for(int i=0;i<k-1;i++)
{
if((s[i]=='V'||s[i+1]=='K')&&a[i]==0&&a[i+1]==0)
{
ans++;
break;
}
}
printf("%d\n",ans);
} return 0;
}
Codeforces801A Vicious Keyboard 2017-04-19 00:16 241人阅读 评论(0) 收藏的更多相关文章
- Python解析HDF文件 分类: Python 2015-06-25 00:16 743人阅读 评论(0) 收藏
前段时间因为一个业务的需求需要解析一个HDF格式的文件.在这之前也不知道到底什么是HDF文件.百度百科的解释如下: HDF是用于存储和分发科学数据的一种自我描述.多对象文件格式.HDF是由美国国家超级 ...
- Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- OC基础:Date 分类: ios学习 OC 2015-06-22 19:16 158人阅读 评论(0) 收藏
NSDate 日期类,继承自NSObject,代表一个时间点 NSDate *date=[NSDate date]; NSLog(@"%@",date); //格林尼治时间, ...
- HDU4081 Qin Shi Huang's National Road System 2017-05-10 23:16 41人阅读 评论(0) 收藏
Qin Shi Huang's National Road System ...
- 公众号第三方平台开发 获取 component_verify_ticket 2015-07-05 10:16 59人阅读 评论(0) 收藏
8.推送component_verify_ticket协议 在公众号第三方平台创建审核通过后,微信服务器会向其"授权事件接收URL"每隔10分钟定时推送component_veri ...
- How to create your own custom 404 error page and handle redirect in SharePoint 分类: Sharepoint 2015-07-08 00:22 4人阅读 评论(0) 收藏
1. In your MOSS server, make a copy of %systemdrive%\Program Files\Common Files\Microsoft Shared\Web ...
- C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏
const是C语言的关键字,经C++进行扩充,变得功能强大,用法复杂.const用于定义一个常变量(只读变量),当const与指针,引用,函数等结合起来使用时,情况会变得复杂的多.下面将从五个方面总结 ...
- 自动化测试工具QTP的使用实例 分类: 软件测试 2015-06-17 00:23 185人阅读 评论(0) 收藏
1. QTP简介 1.1QTP功能与特点 QTP是QuickTest Professional的简称,是一种自动化软件测试工具.在软件的测试过程中,QTP主要来用来通过已有的测试脚本执行重复的手动测试 ...
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛--n a^o7 ! 分类: 比赛 2015-06-09 17:16 14人阅读 评论(0) 收藏
n a^o7 ! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 All brave and intelligent fighte ...
随机推荐
- How to Pronounce the word BECAUSE
How to Pronounce the word BECAUSE Share Tweet Share Tagged With: BECAUSE Reduction Study the BECAUSE ...
- 批量压缩文件.net
C#调用 ICSharpCode.SharpZipLib.Zip 实现解压缩功能公用类 最近想用个解压缩功能 从网上找了找 加自己修改,个人感觉还是比较好用的,直接上代码如下 using System ...
- python 写hive循环脚本
要一个月的数据 一次跑一周的数据 ,建表用插入数据的方法: import os, sys reload(sys); sys.setdefaultencoding( "utf-8" ...
- blat
1) 产生背景---------------------------------------------------2002年的时候,随着人类基因组项目不断推进,需要将大量ESTs(300万) 及m ...
- Quartz入门
Quartz体系结构: 明白Quartz怎么用,首先要了解Scheduler(调度器).Job(任务)和Trigger(触发器)这3个核心的概念.请注意加粗内容. 1. Job: 是一个接口,只定义一 ...
- eclipise快捷键,留给以后备用
快捷键无效解决办法: 1.考虑是否被其他应用占用,如QQ,QQ音乐,千千动听等 2.在eclispe查看是否被修改:Window->Preferences->General->Key ...
- Appium原理初步--Android自动化测试学习历程
章节:自动化基础篇——Appium原理初步(第七讲) 本期关键词: Appium.跨语言跨平台.Bootstrap 主要讲解内容及笔记: 一.what is appium 一种封装了uiautomat ...
- 【原创】有关Silverlight中 "Silverlight提示4004错误" 的解决方案及思路。
今天下午再改一个页面xaml时没注意一个细节导致了这个错误,整整搞了1个小时.在这给大家参考参考. 出错原因: 总结:其实silverlight已经提示了 出错的细节信息了,没必要因为silverli ...
- centos7之iptables与firewalld
保障数据的安全性是继保障数据的可用性之后最为重要的一项工作.防火墙作为公网 与内网之间的保护屏障,在保障数据的安全性方面起着至关重要的作用. firewalld与iptables iptables f ...
- linux信号处理总结
本文主要讲解常见信号的处理方式. Sighup:终端关闭时,发送给此会话的所有进程组.Setsid成功后不再属于该会话,收不到该消息. Sigterm: kill process_id时产生. Si ...