【CUGBACM15级BC第三场 B】hdu 4908 BestCoder Sequence
来源:互联网 发布:5.1音响推荐 知乎 编辑:程序博客网 时间:2024/06/07 11:35
BestCoder Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2140 Accepted Submission(s): 703
Total Submission(s): 2140 Accepted Submission(s): 703
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 asBestcoder Sequence.
As the best coder, Mr potato has strong curiosity, he wonder the number of consecutive sub-sequences which arebestcoder sequences in a given permutation of 1 ~ N.
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 asBestcoder Sequence.
As the best coder, Mr potato has strong curiosity, he wonder the number of consecutive sub-sequences which arebestcoder 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
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 theBestcoder Sequences.
Sample Input
1 115 34 5 3 2 1
Sample Output
13HintFor the second case, {3},{5,3,2},{4,5,3,2,1} are Bestcoder Sequence.
题意:
给一个序列,里面是1~N的排列,给出M,问以M为中位数的奇数长度的序列个数。
分析:
就是记录M左右两边区间比M大的和比M小的差值的个数,再相乘。
可以先遍历左边记录差值个数,右边遍历直接加上左边的一样的差值
给一个序列,里面是1~N的排列,给出M,问以M为中位数的奇数长度的序列个数。
分析:
就是记录M左右两边区间比M大的和比M小的差值的个数,再相乘。
可以先遍历左边记录差值个数,右边遍历直接加上左边的一样的差值
#include <iostream>#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <algorithm>#include <functional>#define PI acos(-1)#define eps 1e-8#define inf 0x3f3f3f3f#define debug(x) cout<<"---"<<x<<"---"<<endltypedef long long ll;using namespace std;const int maxn = 40010;int sum[maxn];int cnt[maxn * 2];int n, m;int val, p;int main(){ while (scanf("%d%d", &n, &m) == 2) { sum[0] = 0; for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1]; scanf("%d", &val); if (val < m) { sum[i]--; } else if (val > m) { sum[i]++; } else { p = i; } } memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < p; i++) { cnt[sum[i] + maxn]++; } int ans = 0; for (int i = p; i <= n; i++) { ans += cnt[sum[i] + maxn]; } printf("%d\n", ans); } return 0;}
阅读全文
0 0
- 【CUGBACM15级BC第三场 B】hdu 4908 BestCoder Sequence
- 【CUGBACM15级BC第13场 B】hdu 5063 Operation the Sequence
- 【CUGBACM15级BC第23场 B】hdu 5147 Sequence II
- 【CUGBACM15级BC第23场 A】hdu 5146 Sequence
- 【CUGBACM15级BC第三场 A】hdu 4907 Task schedule
- 【CUGBACM15级BC第15场 B】hdu 5082 Instruction
- 【CUGBACM15级BC第17场 B】hdu 5101 Select
- 【CUGBACM15级BC第20场 B】hdu 5124 lines
- 【CUGBACM15级BC第26场 B】hdu 5159 Card
- 【CUGBACM15级BC第28场 B】hdu 5167 Fibonacci
- 【CUGBACM15级BC第36场 B】hdu 5199 Gunner
- HDU 4908/BC B BestCoder Sequence
- 【CUGBACM15级BC第12场 B】hdu 5059 Help him
- 【CUGBACM15级BC第11场 B】hdu 5055 Bob and math problem
- 【CUGBACM15级BC第18场 B】hdu 5105 Math Problem
- 【CUGBACM15级BC第22场 B】hdu 5143 NPY and arithmetic progression
- 【CUGBACM15级BC第25场 B】hdu 5155 Harry And Magic Box
- 【CUGBACM15级BC第27场 B】hdu 5163 Taking Bus
- 送给1周岁的儿子
- python encode和decode函数说明
- Java设计模式之观察者模式
- python基础03--异常处理
- tag()参数详解
- 【CUGBACM15级BC第三场 B】hdu 4908 BestCoder Sequence
- 表加外键的限制
- java乱码问题处理
- prototype和__proto
- Python数据挖掘学习03--pandas模块数据的导入实战
- Clip Related Script
- 本地Navicat for Mysql 连接不上远程阿里云服务器mysql(windows系统)
- Hadoop新手学习指导-入门需知
- jq拖拽事件