codeforces 318 A.Even Odds B.Sereja and Array
给你n和k, 把从1到n先排奇数后排偶数排成一个新的序列,输出第k个位置的数。
比如 10 3 拍好后就是 1 3 5 7 9 2 4 6 8 10 第3个数是5。
//cf 318 A
//2013-06-18-20.30
#include <iostream>
using namespace std;
int main()
{
__int64 n, k;
while (cin >> n >> k)
{ if (k <= (n+1)/2)
cout << (k-1)*2 + 1 << endl;
else
{
k -= (n+1)/2;
cout << k*2 << endl;
}
}
return 0;
}
就是找到以“heavy” 开头和“metal”结尾的字符串有多少个。
我的思路是标记“heavy” 和“metal”的位置然后计算以每一个“metal”结尾的有多少个,然后相加。
//cf 318 B
//2013-06-18-21.01
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std; const int maxn = 1000006;
char str[maxn];
int s[maxn];
int e[maxn]; int main()
{
while (scanf("%s", str) != EOF)
{
memset(s, 0, sizeof(s));
memset(e, 0, sizeof(e));
int l = strlen(str);
for (int i = 0; i < l-4; i++)
{
if (str[i] == 'h' && str[i+1] == 'e' && str[i+2] == 'a' && str[i+3] == 'v' && str[i+4] == 'y')
{
s[i] = 1;
i += 4;
continue;
}
if (str[i] == 'm' && str[i+1] == 'e' && str[i+2] == 't' && str[i+3] == 'a' && str[i+4] == 'l')
{
e[i] = 1;
i += 4;
continue;
}
}
__int64 ans = 0;
for (int i = 1; i < l; i++)
{
if (e[i])
ans += s[i-1];
s[i] += s[i-1];
}
cout << ans << endl;
}
return 0;
}
codeforces 318 A.Even Odds B.Sereja and Array的更多相关文章
- Codeforces Round #243 (Div. 1)A. Sereja and Swaps 暴力
A. Sereja and Swaps time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes map
B. Sereja and Suffixes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- Codeforces Round #215 (Div. 1) B. Sereja ans Anagrams 匹配
B. Sereja ans Anagrams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- Codeforces Round #223 (Div. 2) E. Sereja and Brackets 线段树区间合并
题目链接:http://codeforces.com/contest/381/problem/E E. Sereja and Brackets time limit per test 1 secon ...
- Codeforces Round #223 (Div. 2)--A. Sereja and Dima
Sereja and Dima time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #215 (Div. 2) D. Sereja ans Anagrams
http://codeforces.com/contest/368/problem/D 题意:有a.b两个数组,a数组有n个数,b数组有m个数,现在给出一个p,要你找出所有的位置q,使得位置q q+ ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round #243 (Div. 2) A. Sereja and Mugs
#include <iostream> #include <vector> #include <algorithm> #include <numeric> ...
随机推荐
- Spark学习之路(十三)—— Spark Streaming 与流处理
一.流处理 1.1 静态数据处理 在流处理之前,数据通常存储在数据库,文件系统或其他形式的存储系统中.应用程序根据需要查询数据或计算数据.这就是传统的静态数据处理架构.Hadoop采用HDFS进行数据 ...
- 系统学习 Java IO (五)----使用 SequenceInputStream 组合多个流
目录:系统学习 Java IO---- 目录,概览 SequenceInputStream 可以将两个或多个其他 InputStream 合并为一个. 首先,SequenceInputStream 将 ...
- yii中获取当前模块,控制器,方法
在控制器里 $name = $this->getModule()->id; // module $name = $this->getId(); // controller $nam ...
- 透过字节码分析java基本类型数组的内存分配方式。
我们知道java中new方式创建的对象都是在堆中创建的,而局部变量对应的值存放在栈上.那么java中的int [] arr={1,2,3}是存放在什么地方的呢,int []arr = new int[ ...
- 2018.10.1 2018NOIP冲刺之立体图
2008NOIP普及组立体图 请自行百度(事实上放不下了) 图不是很清楚 下面有 [输入] 输入文件 drawing.in 第一行有用空格隔开的 2 个整数 m 和 n,表示有 m*n 个格子 (1 ...
- apache开启vhost后localhost和127.0.0.1无法访问
自己单独搭建了php+mysql+apach+windows环境:后面又开启apache的虚拟主机vhost;然后自己配置虚拟主机站点可以正常访问,但是localhost和127.0.0.1无法访问, ...
- Bzoj 3654 图样图森波 题解
3654: 图样图森破 Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 123 Solved: 66[Submit][Status][Discuss] ...
- ESXI好好研究
之前几周在公司要搭建一个平台,因为服务器不够用,所以需要要一台服务器上装虚拟机.有人说用ESXI装虚拟机,并且不用装操作系统,我当时还纳闷儿了,不装操作系统,直接装虚机?这里我有点孤陋寡闻了,其实ES ...
- Kafka【入门】就这一篇!
为获得更好的阅读体验,建议您访问原文地址:传送门 前言:在之前的文章里面已经了解到了「消息队列」是怎么样的一种存在(传送门),Kafka 作为当下流行的一种中间件,我们现在开始学习它! 一.Kafka ...
- Day1 -Python program
采用python 3.5 用PyCharm编译 第一串代码 print ("hello,world!") 练习1 输入一个用户名和密码,如果输入正确,就欢迎登陆,否则就显示错误. ...