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轮构成,使用常见的“加权 ...
随机推荐
- CENTOS7错误:Cannot find a valid baseurl for repo: base/7/x86_6
CENTOS7错误:Cannot find a valid baseurl for repo: base/7/x86_6 解决办法: 1.进入/etc/sysconfig/network-script ...
- 转:EditPuls 5.0 注册码
EditPlus5.0注册码 注册名 Vovan 注册码 3AG46-JJ48E-CEACC-8E6EW-ECUAW EditPlus3.x注册码 EditPlus注册码生成器链接 http://ww ...
- 数据执行保护呈灰色无法开启 用命令BCEDIT无效 请问怎么解决?
1.默认的管理员账号是关闭开不了的. 2.你重新创建个管理员账户. 3.然后登陆这个账号. 4.然后打开cmd 输入 bcdedit /set nx optin alwaysoff 这行指令.然后回车 ...
- LeetCode算法题-Balanced Binary Tree(Java实现)
这是悦乐书的第167次更新,第169篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第26题(顺位题号是110).给定二叉树,判断它是否是高度平衡的.对于此问题,高度平衡二 ...
- 【ctags/cscope/project安装使用】给神编辑器vim添加新的翅膀
本文地址 分享提纲: 1.安装 2.使用cscope 3.使用project 1.安装 1.1)linux(yum下安装) yum -y install cscope 1.2)linux(unbunt ...
- keepalived 安装篇-官方文档
官方安装文档 http://www.keepalived.org/doc/installing_keepalived.html Installing Keepalived Install keepal ...
- Loj#6183. 看无可看
Loj#6183. 看无可看 题目描述 首先用特征根求出通项公式\(A_n=p\cdot 3^n+q\cdot(-1)^n\).通过给定的\(f_0,f_1\)可以解出\(p,q\). 然后我们要求的 ...
- 冒泡排序 最好O(n)平均O(n^2) 选择排序O(n2) 插入排序O(n2)
LOWB 三人组 分清有序区跟无序区 冒泡排序 思路: 首先,列表每两个相邻的数,如果前边的比后边的大,那么交换和两个数.... 冒泡排序优化 如果一趟没有发生任何交换 那么证明列表已经是有序的了 i ...
- Python之TabError: inconsistent use of tabs and spaces in indentation和ModuleNotFoundError:No module named 'win32api'
1.TabError: inconsistent use of tabs and spaces in indentation 这是我的代码,感觉没啥不对, 后来运行之后出现了下面的错误,我也是弄了好久 ...
- Node.js使用TCP通讯
原文地址:https://www.cnblogs.com/ay-a/p/9822057.html Node.js 的 net 模块可以方便的创建TCP 服务,,以下是使用 net 模块创建的tcp 服 ...