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. c#基础汇总-------------封装

    说到封装,其实是比较基础类的问题,它为程序设计提供了系统与系统,模块与模块,类与类之间交互的实现手段.在.Net中,一切看起来都已经被包装在.Net FrameWork这一复杂的网络中,提供给最终开发 ...

  2. 函数 resize和reserve的区别

    reserve是容器预留空间,但在空间内不真正创建元素对象,所以在没有添加新的对象之前,不能引用容器内的元素.加入新的元素时,要调用push_back()/insert()函数. resize是改变容 ...

  3. SublimeText更换皮肤

    SublimeText是一款非常好用的文本编辑工具,官方网址http://www.sublimetext.com/. 这里介绍一下手动安装SublimeText皮肤的方法. (1)首先找一款你喜欢的皮 ...

  4. 用C#对ADO.NET数据库完成简单操作

    数据库访问是程序中应用最普遍的部分.随着C#和ADO.NET的引入,这种操作变得更简单.这篇文章将示范四种最基础的数据库操作. ● 读取数据.其中包括多种数据类型:整型,字符串,日期型. ● 写数据. ...

  5. mouseenter 事件,固定右侧客服特效

    不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件. 只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件. 当鼠标指针离开元素时,会发生 mouseleave 事件 ...

  6. gson小练习之嵌套复杂数据解析

    package com.zf.demo; import java.util.List; import com.google.gson.Gson; public class JGson { /** * ...

  7. js 根据当前星期做跳转(代码段)

    var week = [6,0,1,2,3,4,5]; $('.HotShop_head .HotShop_tab:eq('+week[new Date().getDay()]+')').click( ...

  8. C# window service的创建

    其实我也是第一次在博客园写博客,看到那些高手说自己要多动手写博客,于是乎自己也尝试尝试. 废话不多说.这几天在研究window service,通过查找各种大神写的博客,我终于成功的自己写出来了. 下 ...

  9. PS 颜色表大全-颜色中文名(1)

    颜色中文名  鸨色#f7acbc 赤白橡#deab8a 油色#817936 绀桔梗#444693 踯躅色#ef5b9c 肌色#fedcbd 伽罗色#7f7522 花色#2b4490 桜色#feeeed ...

  10. dive into python 读笔(3)

    chapter 6 异常和文件处理: # 使用 try...except 来捕捉异常 # 使用 try...finally 来保护额外的资源 # 读取文件 # 在一个 for循环中一次赋多个值 # 使 ...