HDU4908——BestCoder Sequence(BestCoder Round #3)
BestCoder Sequence
Problem Description
Mr Potato is a coder.
Mr Potato is the BestCoder.
One night, an amazing sequence appeared in his dream. Length of this sequence is odd, the median number is M, and he named this sequence as Bestcoder Sequence.
As the best coder, Mr potato has strong curiosity, he wonder the number of consecutive sub-sequences which are bestcoder sequences in a given permutation of 1 ~ N.
Input
Input contains multiple test cases. 
For each test case, there is a pair of integers N and M in the first line, and an permutation of 1 ~ N in the second line.
[Technical Specification]
1. 1 <= N <= 40000
2. 1 <= M <= N
Output
For each case, you should output the number of consecutive sub-sequences which are the Bestcoder Sequences. 
Sample Input
1 1
1
5 3
4 5 3 2 1
Sample Output
1
3
题目大意:
定义了一种序列,满足:1)有奇数个个数 2)中位数为M
输入一个任意一个数串,输出满足条件的子串个数。
结题思路:
一开始读错题了。后来看了结题报告才过的。
附:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MAXN 50000
using namespace std;
int num[MAXN+],sum[MAXN+],a[MAXN++MAXN];
int main()
{
int M,N,M_id;
while (scanf("%d %d",&N,&M)!=EOF)
{
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
memset(num,,sizeof(num));
num[]=sum[]=;
for (int i=;i<=N;i++)
{
int tmp;
scanf("%d",&tmp);
if (tmp>M) num[i]=;
else if (tmp==M) num[i]=,M_id=i;
else num[i]=-;
sum[i]=sum[i-]+num[i];
}
int cnt=;
for (int j=;j<=M_id-;j++)
a[sum[j]+MAXN]++;
for (int i=M_id;i<=N;i++)
cnt+=a[sum[i]+MAXN];
printf("%d\n",cnt);
}
return ;
}
HDU4908——BestCoder Sequence(BestCoder Round #3)的更多相关文章
- hdu4908 & BestCoder Round #3 BestCoder Sequence(组合数学)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 BestCoder Sequence Time Limit: 2000/1000 MS (Jav ...
 - [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
		
BestCoder Sequence Problem Description Mr Potato is a coder. Mr Potato is the BestCoder. One night, ...
 - 【HDU】4908 (杭电 BC #3 1002题)BestCoder Sequence ——哈希
		
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
 - BestCoder Sequence
		
hdu 4908 Bestcoder Problem Description Mr Potato is a coder.Mr Potato is the BestCoder. One night, ...
 - hdu 4908 BestCoder Sequence  发现M中值是字符串数, 需要预处理
		
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
 - BestCoder3  1002 BestCoder Sequence(hdu 4908)  解题报告
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 题目意思:给出 一个从1~N 的排列你和指定这个排列中的一个中位数m,从这个排列中找出长度为奇数 ...
 - HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分
		
分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可 找第一个点可以二分可以尺取 #include <cstdio> #include <cst ...
 - HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理
		
分析:维护空隙的差,然后预处理前缀最大,后缀最大,扫一遍 #include <cstdio> #include <cstring> #include <cmath> ...
 - 【BestCoder】【Round#41】
		
枚举+组合数?+DP+数学问题 http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=582 QAQ许久没打过比赛,来一发BC,结果还是只 ...
 
随机推荐
- [GeekBand] STL与泛型编程(2)
			
本篇文章在上一篇文章的基础上进一步介绍一些常用的容器以及STL的一些深入知识. 一. Stack和Queue 栈和队列是非常常用的两种数据结构,由deque适配而来.关于数据结构的知识这里就不在介绍了 ...
 - Android 生命周期 和 onWindowFocusChanged
			
转载 http://blog.csdn.net/pi9nc/article/details/9237031 onWindowFocusChanged重要作用 Activity生命周期中,onStart ...
 - php array_walk 和 array_reduce函数
			
1.array_walk:将数组中的元素(键+值)依次取出传给处理的函数,函数处理完就完了,没有返回值. $arr1=array( 'name'=>'zhangsan', 'age'=>3 ...
 - Spark Streaming揭秘 Day27 Job产生机制
			
Spark Streaming揭秘 Day27 Job产生机制 今天主要讨论一个问题,就是除了DStream action以外,还有什么地方可以产生Job,这会有助于了解Spark Streaming ...
 - Ubuntu安装google Gtest
			
(1) 下载源码:http://code.google.com/p/googletest/gtest-1.7.0 (2013)gtest-1.7.0 (2010) (2) README编译指南126 ...
 - 【转】 设定linux 系统可用资源
			
getrlimit和setrlimit函数 每个进程都有一组资源限制,其中某一些可以用getrlimit和setrlimit函数查询和更改. #include #include int getrli ...
 - Error is 10055 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作
			
今天上午,一个同事反映:某系统的某个通过socket来进行通信的服务无法连接上数据库里,在操作系统上用数据库的客户端测试数据库连接也出现这样的错误信息:Error is 10055 由于系统缓冲区空间 ...
 - 【BZOJ 1040】 [ZJOI2008]骑士
			
Description Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬.最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的侵略战争.战火 ...
 - (转)Linux SLUB 分配器详解
			
原文网址:https://www.ibm.com/developerworks/cn/linux/l-cn-slub/ 多年以来,Linux 内核使用一种称为 SLAB 的内核对象缓冲区分配器.但是, ...
 - poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)
			
http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 13 ...