HDU5806 NanoApe Loves Sequence Ⅱ【尺取法+乘法原理】
来源:互联网 发布:淘宝760的lamy2000 编辑:程序博客网 时间:2024/06/05 15:07
NanoApe Loves Sequence Ⅱ
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 1836 Accepted Submission(s): 787
Problem Description
NanoApe, the Retired Dog, has returned back to prepare for for the National Higher Education Entrance Examination!
In math class, NanoApe picked up sequences once again. He wrote down a sequence withn numbers and a number m on the paper.
Now he wants to know the number of continous subsequences of the sequence in such a manner that thek -th largest number in the subsequence is no less than m .
Note : The length of the subsequence must be no less thank .
In math class, NanoApe picked up sequences once again. He wrote down a sequence with
Now he wants to know the number of continous subsequences of the sequence in such a manner that the
Note : The length of the subsequence must be no less than
Inputhttp://write.blog.csdn.net/postedit?ticket=ST-152705-jLaV4MBV1ZmLGwLvy7lI-passport.csdn.net
The first line of the input contains an integer T , denoting the number of test cases.
In each test case, the first line of the input contains three integersn,m,k .
The second line of the input containsn integers A1,A2,...,An , denoting the elements of the sequence.
1≤T≤10, 2≤n≤200000, 1≤k≤n/2, 1≤m,Ai≤109
In each test case, the first line of the input contains three integers
The second line of the input contains
For each test case, print a line with one integer, denoting the answer.
Sample Input
17 4 24 2 7 7 6 5 1
Sample Output
18
Source
BestCoder Round #86
问题链接:HDU5806 NanoApe Loves Sequence Ⅱ
问题简述:在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为n的数列,他又根据心情写下了一个数m。他想知道这个数列中有多少个区间里的第k大的数不小于m,当然首先这个区间必须至少要有k个数。
问题分析:(略)
程序说明:这里给出两种程序,一是尺取法的程序,二是乘法原理的程序。占个位置,以后说明。
题记:(略)参考链接:(略)
AC的C++语言程序如下(尺取法):
/* HDU5806 NanoApe Loves Sequence Ⅱ(尺取法) */#include <iostream>#include <stdio.h>using namespace std;const int N = 200000;int a[N];int main(){ int t, n, m, k; scanf("%d", &t); while(t--) { scanf("%d%d%d", &n, &m, &k); for(int i=0; i<n; i++) scanf("%d", &a[i]); int j=0, num = 0; long long sum = 0; for(int i=0; i<n; i++) { while(j < n && num < k) { if(a[j] >= m) num++; j++; } if(num >= k) sum += n - j + 1; if(a[i] >= m) num--; } printf("%lld\n", sum); } return 0;}
AC的C++语言程序如下(乘法原理):
/* HDU5806 NanoApe Loves Sequence Ⅱ(乘法原理) */#include <iostream>#include <stdio.h>using namespace std;const int N = 200000;int a[N];long long d[N];int main(){ int t, n, m, k; scanf("%d", &t); while(t--) { scanf("%d%d%d", &n, &m, &k); int j=0; long long sum=0; for(int i=0; i<n; i++) { scanf("%d", &a[i]); if(a[i] >= m) { d[j++] = i + 1; if(j == k) sum += d[0] * (n - i); else if(j > k) sum += (d[j - k] - d[j - k - 1]) * (n - i); } } printf("%lld\n", sum); } return 0;}
阅读全文
0 0
- HDU5806 NanoApe Loves Sequence Ⅱ【尺取法+乘法原理】
- HDU5806 NanoApe Loves Sequence Ⅱ(尺取法\two pointers)
- HDU5806 NanoApe Loves Sequence Ⅱ
- hdu 5806 NanoApe Loves Sequence Ⅱ(乘法原理/尺取法)
- hdoj5806 NanoApe Loves Sequence Ⅱ(尺取法)
- NanoApe Loves Sequence Ⅱ(尺取法)
- hdu5806 NanoApe Loves Sequence Ⅱ 前缀和 + 二分
- HDU5806 NanoApe Loves Sequence Ⅱ BestCoder Round #86 two-pointer
- HDU 5806 NanoApe Loves Sequence Ⅱ [尺取法]
- HDU 5806 NanoApe Loves Sequence Ⅱ(尺取法)
- hdu 5806 NanoApe Loves Sequence Ⅱ (尺取法)
- (尺取法)HDU - 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ (尺取法)
- hdu 5806 NanoApe Loves Sequence Ⅱ 前缀和+尺取法
- 【HDU】5806 - NanoApe Loves Sequence Ⅱ(尺取法)
- HDU 5806 NanoApe Loves Sequence Ⅱ尺取法
- hdu 5806 NanoApe Loves Sequence Ⅱ 尺取法
- hdu 5806 NanoApe Loves Sequence Ⅱ(二分或尺取法)
- Git-将已有的项目转换为GIT项目托管到 GITHUB 仓库
- 并查集
- springboot maven指定jar包的选择
- ubuntu17.04 使用 steam 玩游戏时字体无显示解决办法
- 图片间有空隙的解决方法
- HDU5806 NanoApe Loves Sequence Ⅱ【尺取法+乘法原理】
- PX4代码学习系列博客(2)——PX4与实时操作系统
- 逻辑运算符 或 与 非 位运算
- 滚动数组
- UVALive6336 HDU4450 Draw Something【水题】
- [MySQL] case问题
- 一点感悟
- linux 下查看共享内存的使用以及删除共享内存
- 移动端证件识别智能图文处理