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> ...
随机推荐
- Spring 5.x 、Spring Boot 2.x 、Spring Cloud 与常用技术栈整合
项目 GitHub 地址:https://github.com/heibaiying/spring-samples-for-all 版本说明: Spring: 5.1.3.RELEASE Spring ...
- vuex分模块4
Vuex下Store的模块化拆分实践 https://segmentfault.com/a/1190000007667542 vue.js vuex 猫切 2016年12月02日发布 赞 | 1 ...
- Paxos算法——前世
Paxos算法是基于消息传递且具有高度容错特性的一致性算法.我们将从一个简单的问题开始,逐步的改进我们的设计方案,最终得到Paxos,一个可以在逆境下工作的协议. 一.客户端-服务器模型 我们从最小的 ...
- zabbix2.4汉化
zabbix的2.4版本安装完后,这里的语言界面选择没有中文,其实是这个版本把中文的屏蔽了. [root@zabbix-server opt]# vim /var/www/html/include/l ...
- Excel导出打印失败报错 (eg HSSF instead of XSSF)
错误信息: java.lang.RuntimeException: org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: ...
- Django项目的创建和管理
1.主题 这部分教程主要介绍如何通过Pycharm创建.管理.运行一个Django工程.对于Django模块的相关知识大家可以参考Python社区. 2.准备环境 Django版本为2.0或更高 Py ...
- c++快速排序算法
c++快速排序算法 题目描述 利用快速排序算法将读入的NN个数从小到大排序后输出. 快速排序是信息学竞赛的必备算法之一.对于快速排序不是很了解的同学可以自行上网查询相关资料,掌握后独立完成.(C++选 ...
- 新手上路—Java的"瑞士军刀"
“ Jodd 是一个开源的 Java 工具集, 包含一些实用的工具类和小型框架.简单,却很强大!这在我们的日常开发工作中,无疑是如虎添翼,事半功倍. Jodd = Tools + IoC + MVC ...
- web应用分页
1. 场景描述 目前大部分的应用程序中都会用到分页功能,以便减少前端浏览器及后台服务器的压力,以及其他方面的考虑. (1)分页从概念上可分为逻辑分页和物理分页,逻辑分页主要是通过应用程序(前端或者后端 ...
- Mybatis辅助神器-MyBatis Log Plugin
1. 问题描述 Java操作数据库的两台流行天王-mybatis和hibernate,mytabis和hibernate的区别不想废话了,以前用hibernate,最近几年一直用的mybatis,目前 ...