Vicious Keyboard CodeForces - 801A (暴力+模拟)
题意:
给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串?
思路:
由于数据量很小,不妨尝试暴力写。首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的字符,然后暴力算出有多少个VK,取出这些答案中 的最大值,即是答案。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb std::ios::sync_with_stdio(false)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char s[maxn];
int len;
int main()
{
scanf("%s",s);
len=strlen(s);
int ans=;
int cnt;
for(int i=;i<=len;i++)
{
if(s[i]=='V')
{
s[i]='K';
}else
{
s[i]='V';
}
cnt=;
for(int j=;j<len-;j++)
{
if(s[j]=='V'&&s[j+]=='K')
{
cnt++;
}
}
if(s[i]=='V')
{
s[i]='K';
}else
{
s[i]='V';
}
ans=max(ans,cnt);
}
printf("%d\n",ans );
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
Vicious Keyboard CodeForces - 801A (暴力+模拟)的更多相关文章
- AC日记——Vicious Keyboard codeforces 801a
		
801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...
 - Codeforces 801 A.Vicious Keyboard  &  Jxnu Group Programming Ladder Tournament 2017江西师大新生赛 L1-2.叶神的字符串
		
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
 - codeforces 591B Rebranding (模拟)
		
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
 - bnuoj 20832 Calculating Yuan Fen(暴力模拟)
		
http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...
 - POJ 1013 小水题 暴力模拟
		
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35774 Accepted: 11 ...
 - hdu_1006 Tick and Tick(暴力模拟)
		
hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...
 - Codeforces801A Vicious Keyboard                                                                                            2017-04-19 00:16             241人阅读              评论(0)              收藏
		
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
 - hihoCoder #1871 : Heshen's Account Book-字符串暴力模拟 自闭(getline()函数) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B) 2018 ICPC 北京区域赛现场赛B
		
P2 : Heshen's Account Book Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Description H ...
 - 美团2018年CodeM大赛-资格赛 分数 暴力模拟
		
链接:https://www.nowcoder.com/acm/contest/138/D来源:牛客网 小胖参加了人生中最重要的比赛——MedoC资格赛.MedoC的资格赛由m轮构成,使用常见的“加权 ...
 
随机推荐
- PostgreSQL分页
			
转自 https://blog.csdn.net/tomcat_2014/article/details/49947711 如果用过mysql,那么对 select * from xxx limit ...
 - js中图片上传,多次上传同一张不生效
			
在做图片上传的功能时, 使用删除功能删除了一张图片, 然后想重新上传原来删除的图片, 结果预览不显示, 也不能上传成功 解决办法, 在删除方法里置空input $("#id").f ...
 - Linux 简介(day1)
			
一.Linux 诞生于1991年 二.创始人:林纳斯.托瓦茨(Linus Torvalds) 三.logo:企鹅 四.Linux完整系统包括 1.Linux kernel (Linux 内核) 2.f ...
 - html文本格式
 - 贪心——D - Radar Installation
			
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...
 - 详解区块链P2P网络
			
根据前一篇文章<从微观到宏观理解区块链>我们已经了解到,微观上,区块链本质就是一种不可篡改且可追踪溯源的哈希链条:宏观上,还具备了另外三个基本特征:分布式存储.P2P 网络和共识机制.分布 ...
 - centos7下安装docker(17.4docker监控----prometheus)
			
Prometheus是一个非常优秀的监控工具.准确的说,应该是监控方案.Prometheus提供了监控数据搜集,存储,处理,可视化和告警一套完整的解决方案 Prometheus架构如盗图: 官网上的原 ...
 - ASP.Net Web API 输出缓存 转载 -- Output caching in ASP.NET Web API
			
一.Nuget安装相关dll Web API 2 : Install-Package Strathweb.CacheOutput.WebApi2 Web API 1 : Install-Package ...
 - 【vue】vue +element 搭建项目,$createElement使用
			
语法: 它有三个参数 第一个:html标签名 第二个:配置的数据对象 第三个:内容 应用1:自定义弹窗 html: <el-button type="text" @click ...
 - Visual Studio 2013 编译 64 位 Python 的 C 扩展 (使用 PyObject 包装)
			
对于 32 位 Python 的 C 扩展,以前用过 mingW32 编译, 但是 mingW32 不支持 64 位 Python 的 C 扩展编译,详情可见 stackoverflow,这位前辈的大 ...