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. browserify总结

    一.browserify 简介 browserify is a tool for compiling node-flavored commonjs modules for the browser. Y ...

  2. C语言中fgetc、fputc和getc、putc的区别是什么

    看书的时候,发现了这四个函数,想知道他们的不同.结果上网查发现很多人说fgetc.fputc的f代表的是file,就是这两个函数是和文件有关的!但是一看他们的函数声明,如下图: 发现他们的参数里面都有 ...

  3. fedora下python3 安装tkinter和pygame

    root 下用 “yum search tkinter”,如下图所示: 然后再根据系统选择安装就好了. tkinter安装完毕. 接下来是安装pygame在fedora的python3上,我的是pyt ...

  4. 进度条轮播【BackgroundColor】

    直接贴代码先看 HTML: <div class="bannar"> <div class="img"> <ul> < ...

  5. javascript 代码优化工具 UglifyJS

    安装: 1. 安装 node.js 环境 (这个不用我教了吧,网上教程一大堆哦.) 2. 进入 https://github.com/mishoo/UglifyJS  右上角 “Download” Z ...

  6. sizeof() 之 数组

    在平时的编程中,我们会经常用到数组,并且需要知道数组的长度,有时我们可以明确的知道数组的长度,但有时并不,这时,可以借用sizeof(),来获得数组的长度,如下: arrayLength = size ...

  7. WeX5与阿里内测的Weex与有何纠葛?快来看HTML5开发圈那些逗逼事儿!

    4月21日~23日,由infoQ主办的2016 Qcon大会北京站如期举行. HTML5开发已经成为移动开发/前端专题中无可争议的焦点,核心议题已经由前几年的是否该用HTML5转向了如何高性能.高效率 ...

  8. php计算代码运行时间与内存使用的一段代码

    计算运行时间及内存使用,代码如下: <?php //开始计时 $HeaderTime = microtime(true);//参数true表示返回浮点数值 //代码 //... printf(& ...

  9. Python urllib2 模块学习笔记

    2015.3.6  urllib2的使用方法大致如下 # 定制Handler处理函数 opener = urllib2.build_opener(ProxyHandler, HTTPHandler) ...

  10. Django文档——Model字段选项(Field Options)

    建立一个简易Model class Person(models.Model): GENDER_CHOICES=( (1,'Male'), (2,'Female'), ) name=models.Cha ...