CSUOJ 1170 A sample problem
J: A Simple Problem
Submit Page Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 87 Solved: 12
Description
在一个由N个整数组成的数列中,最多能找到多少个位置连续的整数且其中的最大值与最小值之差不超过K呢?
Input
输入包含若干组数据。每组数据的第一行有2个正整数,N(1<=N<=10^6),K(0<=K<=10^6),其中N、K的含义同上,接下来一行一共有N个32位有符号整数(32-bit signed integer),依次描绘了这个数列中各个整数的值。
Output
对于每组数据,输出一个正整数,表示在这个数列中最多能找到多少个位置连续的整数且其中的最大值与最小值之差不超过K。
Sample Input
4 2
3 1 5 2 3 2
3 1 2
Sample Output
2
3
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
char s[],c[];
const int MAXN=;
ll A[MAXN];
int main(){
ll x,y;
ll maxx=-,minn=;
/*set和multiset 会根据特定的排序准则,
自动将元素排序。两者不同之处,
在于multiset允许元素重复,而set不允许重复*/
multiset<ll> ss;
while(scanf("%lld%lld",&x,&y) !=EOF){
for(int i=;i<x;i++){
scanf("%lld",&A[i]);
}
ll nlen=;
ll maxi=,mini=;
ll left=,right=;
ss.insert(A[]);
while(right != x){
maxx=*(--ss.end());
minn=*ss.begin();
if(maxx-minn<=y){
nlen=right-left+>nlen?right-left+:nlen;
ss.insert(A[++right]);
}
else{
auto pos=ss.find(A[left++]);
ss.erase(pos);
}
}
cout<<nlen<<endl;
ss.clear();
}
return ;
}
CSUOJ 1170 A sample problem的更多相关文章
- CSU OJ 1340 A Sample Problem
Description My girlfriend loves 7 very much, she thinks it is lucky! If an integer contains one or m ...
- CSUOJ 1341 String and Arrays
Description 有一个N*N的字符矩阵,从上到下依次记为第1行,第2行,--,第N行,从左至右依次记为第1列,第2列,--,第N列. 对于这个矩阵会进行一系列操作,但这些操作只有两类: ...
- A trip through the Graphics Pipeline 2011_08_Pixel processing – “fork phase”
In this part, I’ll be dealing with the first half of pixel processing: dispatch and actual pixel sha ...
- MYSQL异常和错误机制
BEGIN ; ; ; START TRANSACTION; call put_playerbehavior(i_playerid,i_gameid,i_channelid,i_acttime,@a) ...
- [译]Java 设计模式之适配器
(文章翻译自Java Design Pattern: Adapter) 适配器模式在现在的Java框架中被频繁的用到. 当你想去使用一个存在的类而且它的接口和你需要的不吻合,或者是你想去创建一个可复用 ...
- csu oj 1344: Special Judge
Description Given a positive integer n, find two non-negative integers a, b such that a2 + b2 = n. I ...
- csu oj 1342: Double
Description 有一个由M个整数组成的序列,每次从中随机取一个数(序列中每个数被选到的概率是相等的)累加,一共取N次,最后结果能被3整除的概率是多少? Input 输入包含多组数据. ...
- csu oj 1341 string and arrays
Description 有一个N*N的字符矩阵,从上到下依次记为第1行,第2行,……,第N行,从左至右依次记为第1列,第2列,……,第N列. 对于这个矩阵会进行一系列操作,但这些操作只有两类: (1) ...
- Null Hypothesis and Alternate Hypothesis
1.Null Hypothesis Overview 零假设,H0是普遍接受的事实;这与备择假设(alternate hypothesis)正好相反.研究人员努力否定.驳斥零假设.研究人员提出了另一种 ...
随机推荐
- suggest braces around empty body in an 'if' statement
出现这种错误是要求加大括号
- R绘图 第九篇:绘制散点图和气泡图(ggplot2)
绘制散点图(scatterplots)使用geom_point()函数,气泡图(bubblechart)也是一个散点图,只不过点的大小由一个变量(size)来控制.散点图潜在的最大问题是过度绘图:当一 ...
- REST-framework快速构建API--初体验
一.快速上手 1.环境准备 安装restframework,注册app pip install djangorestframework INSTALLED_APPS = [ 'django.contr ...
- 最简单的iOS网络请求
做iOS开发,说到网络请求,大家可能都不约而同的提到AFN,可以说大家的网络请求都是用AFN封装而成,AFN的强大易用的确很好. 但是版本升级就会出现一些问题,所以就自己基于iOS原生封装了一个网络请 ...
- 解决coursera无法观看视频的问题
问题 最近开始看coursera的一个课程,遇到一个问题,可以正常登录网站(未使用VPN),也可以下载资源(除了视频)但是却没有办法在线观看视频. 解决方法 使用VPN 这个方法应该可以解决任何访问国 ...
- 501. Find Mode in Binary Search Tree【LeetCode by java】
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred ...
- 云容器云引擎:容器化微服务,Istio占C位出道
在精彩的软件容器世界中,当新项目涌现并解决你认为早已解决的问题时,这感觉就像地面在你的脚下不断地移动.在许多情况下,这些问题很久以前被解决,但现在的云原生架构正在推动着更大规模的应用程序部署,这就需要 ...
- About The Algorithm Simplification
For mode 1, you have to ergod all the data in the files. So the key point to solve this problem is t ...
- linux内核分析第一次实验
http://blog.sina.com.cn/s/blog_78e559950102wneg.html
- Daily Scrum - 12/02
Meeting Minutes Shuo终于把文件存取弄好了!Wei大致把后端的代码整合好了,现在是可以基本实现算法的一个简易背单词版本.另外我们又交流了一下UI方面的事情,发现还是有一些问题(特别是 ...