博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #442 (Div. 2) A B
阅读量:5916 次
发布时间:2019-06-19

本文共 3221 字,大约阅读时间需要 10 分钟。

A. Alex and broken contest

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.

But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.

It is known, that problem is from this contest if and only if its name contains one of Alex’s friends’ name exactly once. His friends’ names are “Danil”, “Olya”, “Slava”, “Ann” and “Nikita”.

Names are case sensitive.

Input

The only line contains string from lowercase and uppercase letters and “_” symbols of length, not more than 100 — the name of the problem.

Output

Print “YES”, if problem is from this contest, and “NO” otherwise.

Examples

input
Alex_and_broken_contest
output
NO
input
NikitaAndString
output
YES
input
Danil_and_Olya
output
NO

You need just implement what is written in the statements. Count the total number of entries of the names and check if it’s equal to 1.

开始没有注意同一名字出现多次的情况

#include 
#include
using namespace std;typedef long long LL;int main(){ int ans=0; string s; cin>>s; for(int i=0;i

B. Nikita and string

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day Nikita found the string containing letters “a” and “b” only.

Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters “a” and the 2-nd contains only letters “b”.

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

Input

The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters “a” and “b”.

Output

Print a single integer — the maximum possible size of beautiful string Nikita can get.

Examples

input
abba
output
4
input
bab
output
2
Note
It the first sample the string is already beautiful.
In the second sample he needs to delete one of “b” to make it beautiful.

Let prefa[i] be the count of letter “a” in prefix of length i and prefb[i] be the count of letter “b” in prefix of length i.

Let’s fix two positions i and j, 1 ≤ i ≤ j ≤ n, so we remove all “b” from prefix, which ends in i, and suffix, which starts in j, and all “a” between positions i and j. Then length of string is (prefa[n] - prefa[j]) + (prefb[j] - prefb[i]) + (prefa[i]).
Using two for loops we find optimal i and j and calculate answer.

#include 
#include
using namespace std;typedef long long LL;const int maxn=5005;int suma[maxn],sumb[maxn];int main() { string str; cin>>str; suma[0]=sumb[0]=0; for(int i=1;i<=str.size();i++){ suma[i]=suma[i-1]; sumb[i]=sumb[i-1]; if(str[i-1]=='a'){ suma[i]++; }else { sumb[i]++; } } int n = str.size(); int ans = 0; for(int i=0;i

转载地址:http://drwvx.baihongyu.com/

你可能感兴趣的文章
细说JS数组
查看>>
Adaptive Execution让Spark SQL更高效更好用
查看>>
W3C官方推荐使用新发布的HTML5.2
查看>>
如何应对大促?看京东核心中间件团队的高可用实践指南
查看>>
C# 7.1、7.2特性追踪
查看>>
苏宁的Node.js实践:不低于Java的渲染性能、安全稳定迭代快
查看>>
Jenkins将致力于提升稳定性、易用性和云原生兼容性
查看>>
WebStorm 10支持TypeScript 1.4到JavaScript的实时编译
查看>>
从零开始用Python实现k近邻算法(附代码、数据集)
查看>>
Spring注解@Primary的意思
查看>>
行业看点 | 军事专家:量子技术将引起战争基因突变,颠覆未来战争形态
查看>>
Intel和ARM中国市场的芯片之战一触即发
查看>>
青云QingCloud上海1区正式商用:四大升级 连接未来
查看>>
抓住售后服务 抓住新的收入流
查看>>
【工业串口和网络软件通讯平台(SuperIO)教程】六.二次开发导出数据驱动
查看>>
通过maven-war-plugin插件对war包分环境打包
查看>>
python list排序
查看>>
DELL要开放自己的大门还是要关闭
查看>>
浅谈mysql主从复制高可用
查看>>
轻松扩展家庭无线网络 WiFi更快更稳定
查看>>