题目链接

题意:

给定一个字符串,最多更改一个字符,问最多可以有多少个“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 (暴力+模拟)的更多相关文章

  1. AC日记——Vicious Keyboard codeforces 801a

    801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...

  2. 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 ...

  3. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  4. bnuoj 20832 Calculating Yuan Fen(暴力模拟)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...

  5. POJ 1013 小水题 暴力模拟

    Counterfeit Dollar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35774   Accepted: 11 ...

  6. hdu_1006 Tick and Tick(暴力模拟)

    hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...

  7. 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 ...

  8. 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 ...

  9. 美团2018年CodeM大赛-资格赛 分数 暴力模拟

    链接:https://www.nowcoder.com/acm/contest/138/D来源:牛客网 小胖参加了人生中最重要的比赛——MedoC资格赛.MedoC的资格赛由m轮构成,使用常见的“加权 ...

随机推荐

  1. c/c++线性循环队列

    线性循环队列 队列是先进先出,和栈相反. 线性循环队列,牺牲一个空间,实现循环.比如空间大小为4,牺牲一个空间,所以最多放3个元素. 假设front指向0位置,tail指向3位置 1 2 3 空 出队 ...

  2. Linux端口映射,80端口映射到8080端口

    iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080 其中eth0为外网网卡名称 ipt ...

  3. shell 获取时间

    获取当前时间 t=$(date +"%Y-%m-%d %H-%M-%S") echo $t 获取前一天的当前时间 time=$(date -d "-1 day" ...

  4. 上传--spring-boot

    <dependency>   <groupId>commons-fileupload</groupId>   <artifactId>commons-f ...

  5. input reset 重置时间

    经验规律,301毫秒. function autoFormatMoney() { if (!this.value.length) {return} var num = parseFloat(this. ...

  6. linux学习笔记整理(六)

    第七章 Centos7-文件权限管理本节所讲内容:7.1文件的基本权限:r w x (UGO)7.2文件的特殊权限:suid sgid sticky和文件扩展权限ACL7.3实战:创建一个让root都 ...

  7. css3 object-fit详解

    上传头像的时候遇到了头像变形的问题,最后通过object-fit: cover完美解决了.这个CSS属性可以达到最佳最完美的居中自动剪裁图片的功能. object-fit理解 CSS3 backgro ...

  8. Anaconda的下载与安装

    1.下载地点: 支持国产:https://mirrors.tuna.tsinghua.edu.cn/ Anaconda官网:https://www.anaconda.com/download/ 2.下 ...

  9. 提高git下载速度(非代理或修改HOST)

    1. 利用开源中国提供的代码仓库 标题已经说的很清楚了,我想对于经常使用git的人来讲,很可能已经知道了.对于新手刚接触git的人来讲,可能你只知道github. 实际上,国内也有很多代码仓库提供方, ...

  10. Deep Knowledge Tracing (深度知识追踪)

    论文:Deep Knowledge Tracing    Addressing Two Problems in Deep Knowledge Tracing via Prediction-Consis ...