hdu 4908(思路题)
BestCoder Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1614 Accepted Submission(s): 566
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
1
5 3
4 5 3 2 1
3
For the second case, {3},{5,3,2},{4,5,3,2,1} are Bestcoder Sequence.
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
const int N = ;
int a[N];
int cnt[*N];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
int id = -;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]==m){
id = i;
}
}
memset(cnt,,sizeof(cnt));
int ans = ;
int num = ,j=;
for(int i=id-;i>=;i--){ ///往左计数
j++;
if(a[i]<m) num++;
else num--;
if(num==) ans++;
cnt[N+num]++;
}
num = ,j=;
for(int i=id+;i<=n;i++){
j++;
if(a[i]<m) num++;
else num--;
if(num==) ans++;
ans+=cnt[N-num];
}
printf("%d\n",ans+);
}
}
hdu 4908(思路题)的更多相关文章
- Proud Merchants HDU - 3466 (思路题--有排序的01背包)
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- hdu 5191(思路题)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 5101(思路题)
Select Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu 5063(思路题-反向操作数组)
Operation the Sequence Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4859(思路题)
Goffi and Squary Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu 4956(思路题)
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 5400(思路题)
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 1173 思路题
题目大意 有n个地点(坐标为实数)需要挖矿,让选择一个地点,使得在这个地方建造基地,到n个地点的距离和最短,输出基地的坐标. 题解+代码: 1 /* 2 把这个二维分开看(即把所有点投影到x轴上,再把 ...
- 51nod P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
随机推荐
- [Poj2761]Feed the dogs(主席树)
Desciption 题意:求区间第K小(N<=100000) Solution 主席树模板题 Code #include <cstdio> #include <algorit ...
- [BZOJ3312][USACO]不找零(状压DP)
Description 约翰带着 N 头奶牛在超市买东西,现在他们正在排队付钱,排在第 i 个位置的奶牛需要支付 Ci元.今天说好所有东西都是约翰请客的,但直到付账的时候,约翰才意识到自己没带钱,身上 ...
- 不同项目同一浏览器访问 导致Session覆盖 登录后点击就退出登录问题
产生原因:最近开发项目两个项目部署采用同一个tomcat 部署 (当两个tomcat部署时也会产生)由于部署时候两个项目访问域名相同 localhost:8080/ localhost:8 ...
- laravel5.2总结--软删除
当模型被软删除时,它们并不会真的从数据库中被移除.而是会在模型上设置一个 deleted_at 属性并将其添加到数据库.如果对应模型被软删除,则deleted_at字段的值为删除时间,否则该值为空. ...
- R语言中文社区历史文章整理(类型篇)
R语言中文社区历史文章整理(类型篇) R包: R语言交互式绘制杭州市地图:leafletCN包简介 clickpaste包介绍 igraph包快速上手 jiebaR,从入门到喜欢 Catterpl ...
- APK无源码使用Robotium简单总结
1.使用re-sign.jar对待测包进行重签名,并记录下包名和主Activity名. 2.在Eclipse中点击File-New-Other 选择Android下的Android Test Proj ...
- Python-S9-Day122-Python爬虫
11 初识爬虫 11 初识爬虫 12 今日作业 11.1 初识黄页: 11.2 互联网就是一张大的蜘蛛网: 网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种 ...
- 聊聊、Integer 封装特性
前几天在公司内部群,有人分享出了一道题,问谁能口算出来,他就膜拜那个人.题目如下: Class cache = Integer.class.getDeclaredClasses()[0]: Field ...
- [python][django学习篇][12]继续设计博客首页,点击博客标题能显示文章的详情
回顾一下开发流程:配置url, 编写视图函数,编写对应模板 配置URL 首页视图匹配的 URL 去掉域名后,是一个空的字符串.每篇文章的详情有着不同的 URL,因此可以设计文章详情页面URl:< ...
- 课堂笔记II