BestCoder Sequence
hdu 4908 Bestcoder
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.
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
consecutive sub-sequences which are the Bestcoder Sequences.
#include"iostream"
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int ms=40000;
int sum[ms+1],a[ms+20000];
int n,m;
void solve()
{
memset(sum,0,sizeof(sum));
memset(a,0,sizeof(a));
int x,i,ans=0,id;
for(i=1;i<=n;i++)
{
scanf("%d",&x);
sum[i]=sum[i-1];
if(x==m)
{
id=i;
continue;
}
if(x>m)
sum[i]++;
else
sum[i]--;
}
for(i=0;i<id;i++)
{
a[sum[i]+ms]++;
}
for(i=id;i<=n;i++)
ans+=a[sum[i]+ms];
printf("%d\n",ans);
return ;
}
int main()
{
while(scanf("%d%d",&n,&m)==2)
{
solve();
}
return 0;
}
BestCoder Sequence的更多相关文章
- HDU4908——BestCoder Sequence(BestCoder Round #3)
BestCoder Sequence Problem DescriptionMr Potato is a coder.Mr Potato is the BestCoder.One night, an ...
- 【HDU】4908 (杭电 BC #3 1002题)BestCoder Sequence ——哈希
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 4908 BestCoder Sequence 发现M中值是字符串数, 需要预处理
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
BestCoder Sequence Problem Description Mr Potato is a coder. Mr Potato is the BestCoder. One night, ...
- BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 题目意思:给出 一个从1~N 的排列你和指定这个排列中的一个中位数m,从这个排列中找出长度为奇数 ...
- hdu4908 & BestCoder Round #3 BestCoder Sequence(组合数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 BestCoder Sequence Time Limit: 2000/1000 MS (Jav ...
- hdu 4908 BestCoder Sequence
# include <stdio.h> # include <algorithm> using namespace std; int main() { int n,m,i,su ...
- BestCoder Round #3 A,B
A.预处理出来,0(1)输出. Task schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- hdu4908(中位数)
传送门:BestCoder Sequence 题意:给一个序列,里面是1-N的排列,给出m,问以m为中位数的奇数长度的序列个数. 分析:先找出m的位置,再记录左边比m大的状态,记录右边比m大的状态,使 ...
随机推荐
- Java 从单核到多核的多线程(并发)
JAVA 并发编程 最初计算机是单任务的,然后发展到多任务,接着出现多线程并行,同时计算机也从单cpu进入到多cpu.如下图: 多任务:其实就是利用操作系统时间片轮转使用的原理.操作系统通 ...
- Android JNI之调用JAVA方法的返回类型签名
从http://blog.csdn.net/lonelyroamer/article/details/7932787截取的 如何签名: 下面看看Sign签名如何写,来表示要取得的属性或方法的类型. 1 ...
- 国外PHP学习网站书籍资料汇总
这篇文章汇总了全面多样的PHP学习资源,包括书籍.网站.文章等,帮助你提高PHP开发能力,巩固PHP知识.结合上一篇<重磅资料!Github上的PHP资源汇总大全>,一定可以让你的PHP技 ...
- JavaScript如何判断参数为浮点型
在codewars里,确实可以学到很多很酷的方法,例如这一次的题目是判断数字是否为浮点型.我一开始是想有没有原生的js方法,像isNaN(),isFinite(),在前者Infinity是不属于NaN ...
- HDU 4463 Outlets (最小生成树)
题意:给定n个点坐标,并且两个点已经连接,但是其他的都没有连接,但是要找出一条最短的路走过所有的点,并且路线最短. 析:这个想仔细想想,就是应该是最小生成树,把所有两点都可以连接的当作边,然后按最小生 ...
- 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
如果你是maven项目,tomcat在发布项目的时候没有同时发布maven依赖所添加的jar包,你需要设置一下eclipse:项目 —> 属性 -> Deployment Assembly ...
- Android游戏之平台接入的一点记录
最近手头有需要接入多个渠道的工作,我负责的是Android方面的接入,一般来说,渠道是非常多的,每一个渠道调用的接口都不一致,如果每一个渠道都要自己去弄回非常的耗时,所以网上会有一些接入的中间件提供商 ...
- Unity3D之Mecanim动画系统学习笔记(二):模型导入
我们要在Unity3D中使用上模型和动画,需要经过下面几个阶段的制作,下面以一个人形的模型开发为准来介绍. 模型制作 模型建模(Modelling) 我们的美术在建模时一般会制作一个称为T-Pose( ...
- 决定如何开发你的WordPress主题框架
在本系列教程的第一部分,我介绍了不同类型的主题框架并解释了它们是如何工作的. 在你开始建立你的主题框架之前,你需要考虑它是如何工作的,以及它将会被用来做什么,这样你才能从一开始就找到最合适的开发途径. ...
- C#全角半角转换函数
Code#region 全角半角转换 /// <summary> /// 转全角的函数(SBC case) /// </summary> /// <param name= ...