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> ...
随机推荐
- HBase 学习之路(四)—— HBase集群环境配置
一.集群规划 这里搭建一个3节点的HBase集群,其中三台主机上均为Regin Server.同时为了保证高可用,除了在hadoop001上部署主Master服务外,还在hadoop002上部署备用的 ...
- vscode+vagrant+xdebug调试
配置: { "name": "Listen for XDebug", "type": "php", "requ ...
- Demo小细节
(1) 程序如下: public class Example { static int i = 1, j = 2; static { display(i); i = i + j; } static v ...
- Java基础篇01
01. 面向对象 --> 什么是面向对象 面向对象 面向对象程序设计,简称OOP(Object Oriented Programming). 对象: 指人们要研究的任何事物,不管是物理上具体的事 ...
- docker search/pull 报错
docker报错 Get https://registry-1.docker.io/v2/: x509: certificate has expired or is not yet valid 这种错 ...
- Oracle insert all用法简介
insert all是oracle中用于批量写数据的 现在直接通过例子学习一下,比较简单直观,例子来自<收获,不止SQL优化>一书 环境准备 create table t as selec ...
- 6tunnel数据转发
6tunnel 一条命令实现端口映射.数据转发,实现代理服务器功能. 安装脚本 #!/bin/bash DIR=/opt/software INSTALL=6tunnel-master.tar.gz ...
- Postman接口测试_基本功能
一. 安装与更新 1.安装的方式 方式1:chrome插件版本:chrome--->设置--->扩展程序: 方式2:native版本(具有更好的扩展性,推荐使用):https://ww ...
- HDU 1565:方格取数(1)(最大点权独立集)***
http://acm.hdu.edu.cn/showproblem.php?pid=1565 题意:中文. 思路:一个棋盘,要使得相邻的点不能同时选,问最大和是多少,这个问题就是最大点权独立集. 可以 ...
- Gym 101257G:24(尺取)
http://codeforces.com/gym/101257/problem/GGym 101257G 题意:给出n个人,和一个数s,接下来给出每个人当前的分数和输掉的概率.当一个人输了之后就会掉 ...