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)的更多相关文章

  1. hdu4908 &amp; BestCoder Round #3 BestCoder Sequence(组合数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 BestCoder Sequence Time Limit: 2000/1000 MS (Jav ...

  2. [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)

    BestCoder Sequence Problem Description Mr Potato is a coder. Mr Potato is the BestCoder. One night, ...

  3. 【HDU】4908 (杭电 BC #3 1002题)BestCoder Sequence ——哈希

    BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. BestCoder Sequence

    hdu  4908  Bestcoder Problem Description Mr Potato is a coder.Mr Potato is the BestCoder. One night, ...

  5. hdu 4908 BestCoder Sequence 发现M中值是字符串数, 需要预处理

    BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 题目意思:给出 一个从1~N 的排列你和指定这个排列中的一个中位数m,从这个排列中找出长度为奇数 ...

  7. HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分

    分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可 找第一个点可以二分可以尺取 #include <cstdio> #include <cst ...

  8. HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理

    分析:维护空隙的差,然后预处理前缀最大,后缀最大,扫一遍 #include <cstdio> #include <cstring> #include <cmath> ...

  9. 【BestCoder】【Round#41】

    枚举+组合数?+DP+数学问题 http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=582 QAQ许久没打过比赛,来一发BC,结果还是只 ...

随机推荐

  1. 【转】Linux杀死fork产生的子进程的僵尸进程defunct

    僵尸进程 就是 已经结束,但是还没有清理出去的.用kill -9 $PID 也无法杀死. 所以程序中应该避免出现僵尸进程. 用fork之后,父进程如果没有wait /waitpid 等待子进程的话,子 ...

  2. 使用CSS修改HTML5 input placeholder颜色( 转载 )

    问题:Chrome支持input=[type=text]占位文本属性,但下列CSS样式却不起作用: input[placeholder], [placeholder], *[placeholder] ...

  3. Scrapy简介

    什么是Scrapy? Scrapy是一个快速.高级的爬行器和网页抓取框架,用来抓取网站和提取网页中结构化的数据.它被广泛的使用于监控数据采集和自动化测试. 参考:http://scrapy.org/

  4. CentOS安装,更新Python

    1.查看当前Python版本 python -V 2.查看当前CentOS版本 cat /etc/redhat-release 3.安装所有的开发工具包 yum groupinstall " ...

  5. UIImagePickerController拍照与摄像(转)

    转载自:http://blog.sina.com.cn/s/blog_68edaff101019ppe.html (2012-11-23 14:38:40) 标签: ios iphone 拍照 摄像 ...

  6. 【BZOJ 1911】 [Apio2010]特别行动队

    Description Input Output Sample Input 4 -1 10 -20 2 2 3 4 Sample Output 9 HINT   转移方程 f[i]=max(f[j]+ ...

  7. Calendar GData API / Google Calendar Connectors deprecation

    http://googleappsupdates.blogspot.fr/2014/06/calendar-gdata-api-google-calendar.html

  8. Indri中的动态文档索引技术

    Indri中的动态文档索引技术 戴维 译 摘要: Indri 动态文档索引的实现技术,支持在更新索引的同时处理用户在线查询请求. 文本搜索引擎曾被设计为针对固定的文档集合进行查询,对不少应用来说,这种 ...

  9. Telerik RadGridView 右键菜单如何设置?

    问题: 我想去掉红线框住的部分,希望有会的网友帮助我,谢谢! 解决方法: 默认: 修改: [利用 ContextMenuOpening 事件,对应你的项目,你要自己修改那判断的字符串(你的中文)] p ...

  10. Object调用静态方法

    谁说空指针不能调用方法 public class Foo { public static void bar() { System.out.println("bar"); } pub ...