Subsequence——POJ3061
题目:http://poj.org/problem?id=3061
尺取法解题
import java.util.Scanner;;
public class Main {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int test=reader.nextInt();
while(test>0){
int N=reader.nextInt();
int S=reader.nextInt();
long array[]=new long[N];
for(int i=0;i<N;i++){
array[i]=reader.nextLong();
}
long sum=0;
int start=0;
int end=0;
long step=0;
long result=99999999999999L;
while(true){
while(end<N && sum<S){
sum=sum+array[end];
end++;
}
if(sum<S){
break;
}
step=end-start;
result=Math.min(result, step);
sum=sum-array[start];
start++;
}
if(result==99999999999999L){
System.out.println("0");
}else{
System.out.println(result);
}
test--;
}
}
}
20:19:15
2019-02-26
Subsequence——POJ3061的更多相关文章
- poj3061 Subsequence(尺取法)
https://vjudge.net/problem/POJ-3061 尺取发,s和t不断推进的算法.因为每一轮s都推进1所以复杂度为O(n) #include<iostream> #in ...
- poj3061 Subsequence(尺取)
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- POJ3061 Subsequence 尺取or二分
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)
这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...
- POJ3061 Subsequence
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16520 Accepted: 7008 Desc ...
- poj3061 Subsequence【尺取法】
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- poj3061 Subsequence ,尺取法
A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, a ...
- POJ3061——Subsequence(尺取法)
Subsequence POJ - 3061 给定长度为n的数列整数a0,a1,a2-an-1以及整数S.求出总和不小于S的连续子序列的长度的最小值,如果解不存在输出0. 反复推进区间的开头和末尾,来 ...
- [POJ3061]Subsequence(二分,前缀和)
题目链接:http://poj.org/problem?id=3061 题意:给一个长为n的数列和整数s,求一个连续的子序列,使得这个子序列长度最短并且不小于这个整数s. 统计[1~i]的子序列和su ...
随机推荐
- Julia - 函数运算符
Julia 中,大多数运算符都是支持特定语法的函数 && . || 等短路运算是例外,它们不是函数,因为短路求值先算前面的值,再算后面的值 对于函数运算符,可以像其它函数一样,把参数列 ...
- mac jmeter安装
1. 下载jmeter: 2. 通过cmd进入jmeter的bin目录: 3. 在cmd中输入:./jmeter.sh 4. 启动完成.
- ubuntu安装Percona Server
Percona Server是mysql数据库的一个衍生版本,在性能,稳定性和可管理性上都有很大的提升,目前淘宝的mysql数据库就是基于Percona Server,请原谅我这么喜欢研究淘宝的技术. ...
- AE 遍历栅格实现栅格重分类(C#实现)
下面要讲的种重分类方法,网上很多.但是好像 System.Array pSafeArray = pPixelBlock.get_SafeArray(0) as System.Array;这一句一直报下 ...
- ActionMQ5.8.0 JMS实例 手把手详细图解
出自:http://blog.csdn.net/tongjie008/article/details/40687087 ActionMQ 是开源的JMS实现 1.下载ActiveMQ 去官方网站下载: ...
- ffmpeg打开视频解码器失败:Could not find codec parameters for stream 0 (Video: h264): unspecified size
在使用ffmpeg进行拉流分离音视频数据再解码播放操作的时候: 有时候经常会报错: Could not find codec parameters for stream 0 (Video: h264) ...
- hibernate相关方法
uniqueResult() 当确定返回的实例只有一个或者null时 用uniqueResult()方法 代码示例: Session session = factory.openSession(); ...
- dev GridControl显示标题
gridview:ShowViewCaption = TrueViewCation = "32435354354"
- listener does not currently know of SID given in connect descriptor
一次连接数据库怎么也连接不上,查了多方面资料,终于找到答案,总结 首先应该保证数据库的服务启动 在myeclipse的数据库视图中点 右键->new 弹出database driver的窗口, ...
- centos7 安装mysql5.6.32
1. 检查是否存在旧的mysql,执行: rpm -qa|grep -i mysql PS:若存在旧mysql,删除查询到的旧mysql,执行: rpm -e --nodeps XXXX ...