Codeforces Round #442 (Div. 2)
2 seconds
256 megabytes
standard input
standard 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.
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
Alex_and_broken_contest
NO
NikitaAndString
YES
Danil_and_Olya
NO
题意 是否所有名字中只出现一次
AC代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = ;
typedef long long ll;
string a;
string b[]={"Danil","Olya","Slava","Ann","Nikita"};
int main()
{
cin>>a;
int sum=;
for(int i=;i<;i++)
{
if(a.find(b[i])!=-) //find找到子串第一次出现的位置返回下标
sum++;
if(a.rfind(b[i])!=a.find(b[i])) //rfind找到子串最后一次出现的位置返回下标
sum++;
}
if(sum>||sum==)
printf("NO\n");
else
printf("YES\n");
return ;
}
2 seconds
256 megabytes
standard input
standard 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?
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
abba
4
bab
2
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful.
解析 前缀和暴力枚举所有划分
AC代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int a[maxn],b[maxn];
char s[maxn];
int main()
{
while(scanf("%s",s)!=EOF)
{
int len=strlen(s);
a[]=b[]=;
for(int i=;i<len;i++) //一共 len 位 0~len-1
{
a[i+]=a[i]; //a[i]表示第i位之前 不包括第i位 有多少个a
b[i+]=b[i]; //b[i]表示第i位之前 不包括第i位 有多少个b
if(s[i]=='a')
a[i+]++;
else
b[i+]++;
}
int maxx=;
for(int i=;i<=len;i++) //将 len-1位 划分为成 三个区间[1,i-1],[i,j-1],[j,len-1],枚举划分情况
{
for(int j=i;j<=len;j++)
{
int now=a[i]+(b[j]-b[i])+(a[len]-a[j]); //当前情况的长度 a + b + a
maxx=max(maxx,now); //更新最优值
}
}
printf("%d\n",maxx);
}
}
C题 偶奇偶 来炸就好了 一共n+n/2次
AC代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = ;
typedef long long ll;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int ans=n+n/;
printf("%d\n",ans);
for(int i=;i<=n;i++)
{
if(i%==)
printf("%d ",i);
}
for(int i=;i<=n;i++)
{
if(i%==)
printf("%d ",i);
}
for(int i=;i<=n;i++)
{
if(i%==)
{
if(i+>n)
printf("%d\n",i);
else
printf("%d ",i);
}
}
}
return ;
}
Codeforces Round #442 (Div. 2)的更多相关文章
- Codeforces Round #442 Div.2 A B C D E
A. Alex and broken contest 题意 判断一个字符串内出现五个给定的子串多少次. Code #include <bits/stdc++.h> char s[110]; ...
- Codeforces Round #442 (Div. 2) Danil and a Part-time Job
http://codeforces.com/contest/877/problem/E 真的菜的不行,自己敲一个模板,到处都是问题.哎 #include <bits/stdc++.h> u ...
- Codeforces Round #442 (Div. 2) E Danil and a Part-time Job (dfs序加上一个线段树区间修改查询)
题意: 给出一个具有N个点的树,现在给出两种操作: 1.get x,表示询问以x作为根的子树中,1的个数. 2.pow x,表示将以x作为根的子树全部翻转(0变1,1变0). 思路:dfs序加上一个线 ...
- Codeforces Round #442 (Div. 2)A,B,C,D,E(STL,dp,贪心,bfs,dfs序+线段树)
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- 【Codeforces Round #442 (Div. 2) D】Olya and Energy Drinks
[链接] 我是链接,点我呀:) [题意] 给一张二维点格图,其中有一些点可以走,一些不可以走,你每次可以走1..k步,问你起点到终点的最短路. [题解] 不能之前访问过那个点就不访问了.->即k ...
- 【Codeforces Round #442 (Div. 2) C】Slava and tanks
[链接] 我是链接,点我呀:) [题意] 有n个位置,每个位置都可能有不定数量的tank; 你每次可以选择一个位置投掷炸弹. 并且,这个位置上的所有tank都会受到你的攻击. 并且失去一点体力. 然后 ...
- 【Codeforces Round #442 (Div. 2) B】Nikita and string
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举中间那一段从哪里开始.哪里结束就好 注意为空的话,就全是a. 用前缀和优化一下. [代码] #include <bits/ ...
- 【Codeforces Round #442 (Div. 2) A】Alex and broken contest
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意是所有的名字里面,只出现了其中某一个名字一次. [代码] #include <bits/stdc++.h> usin ...
- Codeforces Round #442 (Div. 2) B题【一道模拟题QAQ】
B. Nikita and string One day Nikita found the string containing letters "a" and "b&qu ...
随机推荐
- C# TreeView 控件的综合使用方法
1.概述 该篇文章开发使用的语言c#,环境visualstudio2010,sql数据库.主要内容包括: (1)treeView控件添加根节点.子节点的基本方法,节点的删除. (2)把treeView ...
- Java 集成 速卖通开发.
一.申请成为开发者 申请入口:http://isvhz.aliexpress.com/isv/index.htm 说明文档:http://activities.aliexpress.com/open/ ...
- C 函数参数 char **s与char *s[]
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/126 先来看一个小例子 : 编写函数遍历一个整型数组的元素,数组 ...
- Python学习(五):易忘知识点
1.列表比较函数cmp >>> a = [1,2,3,4] >>> b = [1,2,3,4,5] >>> c = [1,2,3,4] >& ...
- 关于foo的一个面试题
今天看到一个关于foo的一个面试题,赶脚特别有意思 function foo(){// 第16行 getName = function(){console.log(1)} return this } ...
- SQL企业级面试题
链接:90root MySQL企业面试题 1. 开发有一堆数据插入,如何防止插入的中文数据产生乱码? 2. 如何批量更改数据库表的引擎,如:myisam改为innodb 3. 如何批量更改数据库字符集 ...
- 2018年第一篇行动笔记:Reading Log
今天读了盖兆泉的文章<美国教师怎么上阅读课>,觉得干货颇多,不仅仅针对儿童英语阅读,而且对生活的方方面面都有助益. 该文章主要内容摘要如下: 学生需要大量时间阅读 这里的阅读时间是特指花在 ...
- Mac说——关闭SIP
今天在安装keras的时候总是提示numpy无法安装,百度了下,说是新版本的os系统加入了spi机制. 什么是SIP: 系统集成保护(System Integrity Protection,SIP), ...
- 找回Git中丢失的Commit
在使用Git的过程中,有时候会因为一些误操作,比如reset.rebase.merge等.特别是在Commit之后又执行了git reset --hard HEAD强制回滚本地记录以及文件到服务器版本 ...
- 为Python添加中文关键字
狗屎咖啡 2 个月前 原址: https://zhuanlan.zhihu.com/p/31159526 swizl/cnpython 1. 大部分语法,可以按下面方法加同义的中文token第1步. ...