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 ...
随机推荐
- Haskell语言学习笔记(69)Yesod
Yesod Yesod 是一个使用 Haskell 语言的 Web 框架. 安装 Yesod 首先更新 Haskell Platform 到最新版 (Yesod 依赖的库非常多,版本不一致的话很容易安 ...
- scala -- 递归 实现 斐波那契函数
求一个起始为0,1,1,2,3的斐波那契序列 def main(args: Array[String]): Unit = { def fib(n: Int): Int = { if (n == 1) ...
- uwsgi相关问题
启动时报错: !!! no internal routing support, rebuild with pcre support !!!安装时 : sudo pip install uwsgi -I ...
- pandas 语句
1.对于时间格式数据的处理 有些时候time_stamp是object格式,提取相应的日期,小时,星期等: 方法1 from datetime import datetime user_trad[ ...
- auto semicolon insertion 自动分号补齐的坑
今天发现js自动分号补齐的坑,来看如下两段代码: function Hello(){ return { name: ’JavaScript’ }; } alert(Hello()); //输出unde ...
- Maven常用命令及Eclipse应用
一般来说,github上大多的java项目都是使用maven,ant等进行构建的.由于之前没有使用过maven,因此这几天对maven进行了简单的学习.古话说:“温故而知新”,一些命令长时间不使用都会 ...
- nginx的Mainline version、Stable version、Legacy version
Nginx官网提供了三个类型的版本Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版Stable version:最新稳定版,生产环境上建议使用的版 ...
- 参考 - spring boot 静态变量注入值
参考http://blog.csdn.net/zhayuyao/article/details/78553417 @Component public class A { private static ...
- LibreOJ 6282 数列分块入门 6(在线插入在线查询)
题解:还是分块,将每个块存入vector,然后在插入的时候就是sqrt(n)级的重构,如果块太大了,暴力将这个块拆开. 代码如下: #include<cmath> #include< ...
- VS代码页到设计页传值
代码页 public string titleZRclass = ""; 根据条件设置其值 设计页 <%=titleZRclass %>