A.Even Odds

给你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;
}

B.Sereja and Array

就是找到以“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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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+ ...

  7. Codeforces Round #243 (Div. 2) C. Sereja and Swaps

    由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...

  8. Codeforces Round #243 (Div. 2) B. Sereja and Mirroring

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  9. Codeforces Round #243 (Div. 2) A. Sereja and Mugs

    #include <iostream> #include <vector> #include <algorithm> #include <numeric> ...

随机推荐

  1. HBase 学习之路(一)—— HBase简介

    一.Hadoop的局限 HBase是一个构建在Hadoop文件系统之上的面向列的数据库管理系统. 要想明白为什么产生HBase,就需要先了解一下Hadoop存在的限制?Hadoop可以通过HDFS来存 ...

  2. java源码解析之String类(二)

    上一节主要介绍了String类的一些构造方法,主要分为四类 无参构造器:String(),创建一个空字符串"",区别于null字符串,""已经初始化,null并 ...

  3. mysql开启日志查询功能

    set global general_log_file='/tmp/general.lg';set global general_log=on; show global variables like ...

  4. Mysql事务隔离级别和锁机制

    一.Spring支持四种事务隔离级别: 1.ISOLATION_READ_UNCOMMITTED(读未提交):这是事务最低的隔离级别,它充许令外一个事务可以看到这个事务未提交的数据. 2.ISOLAT ...

  5. Python程序中的协程操作-gevent模块

    目录 一.安装 二.Gevent模块介绍 2.1 用法介绍 2.2 例:遇到io主动切换 2.3 查看threading.current_thread().getName() 三.Gevent之同步与 ...

  6. ES5_05_Function扩展

    Function 构造器的语法: 注意: 参数 arg1 , arg2 , argN 被函数使用的参数的名称必须是合法命名的.参数名称是一个有效的JavaScript标识符的字符串,或者一个用逗号分隔 ...

  7. leetcode的Hot100系列--序

    小白程序猿,练练手,做做题目,分享下经验, 有不对的,还请大家能够指出,多多包涵!谢谢!! 先简单,后复杂,循序渐进,希望能够坚持下来, 大家一起进步~~

  8. CentOS7 使用 kubeadm 搭建 k8s 集群

    一 安装Docker-CE 前言 Docker 使用越来越多,安装也很简单,本次记录一下基本的步骤. Docker 目前支持 CentOS 7 及以后的版本,内核要求至少为 3.10. Docker ...

  9. 渐进式web应用开发--拥抱离线优先(三)

    _ 阅读目录 一:什么是离线优先? 二:常用的缓存模式 三:混合与匹配,创造新模式 四:规划缓存策略 五:实现缓存策略 回到顶部 一:什么是离线优先? 传统的web应用完全依赖于服务器端,比如像很早以 ...

  10. android_sdcard读写(一)

    现在的android手机其实就是一个小小的掌上电脑,平时电脑有的硬件它估计也有了.这次本人研究下了其中充当手机硬盘的角色,就是sdcard.这是一个保存应用程序的好地方. 老规矩,上代码,学习代码才是 ...