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轮构成,使用常见的“加权 ...
随机推荐
- c/c++ 线性表之单向循环链表
c/c++ 线性表之单向循环链表 线性表之单向循环链表 不是存放在连续的内存空间,链表中的每个节点的next都指向下一个节点,最后一个节点的下一个节点不是NULL,而是头节点.因为头尾相连,所以叫单向 ...
- AndroidNDK开发中使用CMake编译JNI
虽然一直在做NDK的开发工作,但是由于项目比较久远,都是使用Makefile进行底层编译,对于目前AndroidStudio官方提供的CMake编译方式并不是很了解,现在学习下这种已经不算新潮的新方式 ...
- 我的游戏学习日志3——三国志GBA
我的游戏学习日志3——三国志GBA 三国志GBA由日本光荣公司1991~1995所推出<三国志>系列游戏,该作是光荣在GBA上推出的<三国志>系列作品的第一款.本游戏登场武将总 ...
- 025k个一组翻转链表
#include "000库函数.h" struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), n ...
- Beta阶段 - 博客链接合集
Beta阶段 - 博客链接合集 项目Github地址 安卓端(Stardust):https://github.com/StardustProject/Stardust 服务器端(Gravel):ht ...
- 在win7下python的xlrd和xlwt的安装于应用
1. http://pypi.python.org/pypi/xlwt 和http://pypi.python.org/pypi/xlrd下载xlwt-0.7.4.tar.gz和xlrd-0.7.7. ...
- (转)Spring Boot(十八):使用 Spring Boot 集成 FastDFS
http://www.ityouknow.com/springboot/2018/01/16/spring-boot-fastdfs.html 上篇文章介绍了如何使用 Spring Boot 上传文件 ...
- 通俗易懂的php多线程解决方案
我们在做项目的时候,有些需求,特别是数据的响应处理需要花费大量的时间,由于php是一个短生命周期的脚本语言,到了默认的30秒,php的数据处理还没完成,php的生命周期就结束了.这时需要使用异步并发处 ...
- windows下使用svn命令行
1.安装“Slik-Subversion-1.9.7-win32.zip”,将路径写入windows的path路径 2.在cmd下可以执行svn 3.应为tortoiseSVN的版本比1的版本低,导致 ...
- RestFul风格API(Swagger)--从零开始Swagger
引言:随着技术的革新,现在的系统基本上都是前后端分离,并且在各自的道路上越走越远,而前后端之间通信或者联系的桥梁就是API,而这里基于RESTful风格的API框架就来了!欲知后事如何,客官别急,往下 ...