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 ...
随机推荐
- 消息服务框架(MSF)应用实例之分布式事务三阶段提交协议的实现
一,分布式事务简介 在当前互联网,大数据和人工智能的热潮中,传统企业也受到这一潮流的冲击,纷纷响应国家“互联网+”的战略号召,企业开始将越来越多的应用从公司内网迁移到云端和移动端,或者将之前孤立的IT ...
- SpringMVC底层数据传输校验的方案
团队的项目正常运行了很久,但近期偶尔会出现BUG.目前观察到的有两种场景:一是大批量提交业务请求,二是生成批量导出文件.出错后,再执行一次就又正常了. 经过跟踪日志,发现是在Server之间进行jso ...
- ES6 Proxy和Reflect (上)
Proxy概述 Proxy用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种"元编程"(meta programming),即对编程语言进行编程. Proxy可以理 ...
- NumPy学习笔记 三 股票价格
NumPy学习笔记 三 股票价格 <NumPy学习笔记>系列将记录学习NumPy过程中的动手笔记,前期的参考书是<Python数据分析基础教程 NumPy学习指南>第二版.&l ...
- go generate 生成代码
今后一段时间要研究下go generate,在官网博客上看了Rob Pike写的generating code,花了一些时间翻译了下.有几个句子翻译的是否正确有待考量,欢迎指正. 生成代码 通用计算的 ...
- Oracle添加记录的时候报错:违反完整性约束,未找到父项关键字
今天需要向一个没有接触过的一个Oracle数据库中添加一条记录,执行报错: 分析: 报错的根本原因:未找到父项关键字的原因是因为你在保存对象的时候缺失关联对象. 问题的解决思路:先保存关联对象后再保存 ...
- [编织消息框架][JAVA核心技术]动态代理应用11-水平扩展实现
由于示例,远程服务地址配置在properties文件,通过QMConfig类加载,最优方式是上节介绍过,放在共享内存上,只需要维护一份数据即可,如放在redis上 /** 服务地址<servic ...
- Ubuntu安装微信
1.系统是Ubuntu 16.04 64位系统,在网上先去下载electronic-wechat-Linux https://github.com/geeeeeeeeek/electr ...
- 未能解析此远程名称: 'www.***.com' 解决办法
今天发布网站的时候在本机IIS上调试完全没问题,但发布到远程服务器上却出现了如下错误: 原因:远程服务器的DNS解析失败,不能对类似于'www.***.com' 的网站解析,所以我们要进行手动解析. ...
- HTTP状态码、请求方法、响应头信息
HTTP状态码 当浏览者访问一个网页时,浏览者的浏览器会向网页所在服务器发出请求.当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含HTTP状态码的信息头(server header)用以响应 ...