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 ...
随机推荐
- 一些常用的centos命令,记忆下,属于常用的
一些常用的centos命令,记忆下,属于常用的 查询内网IP hostname -I 查询外网IP curl ifconfig.me 查看硬盘使用情况 df -h 查看系统资源使用率 top 查看系统 ...
- shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决(XML配置)
在使用Shiro框架进行项目整合时,使用注解在使用Shiro框架进行项目整合时,使用注解在使用Shiro框架进行项目整合时,使用注解@RequiresPermissions为方法提供是需要的权限,但是 ...
- flutter 交互提示方式
交互提示方式dialog和snackbar 首先看看dialog的方式 new PopupMenuButton( icon: new Icon(Icons.phone_iphone, color: C ...
- STL : List使用时应注意的问题
这篇文章所述只是本人遇到的问题,仅供参考. #include<list> #include<iostream> using namespace std; class Foo { ...
- inl文件介绍
inl文件是内联函数的源文件.内联函数通常在C++头文件中实现,但是当C++头文件中内联函数过多的情况下,我们想使头文件看起来简洁点,能不能像普通函数那样将内联函数声明和函数定义放在头文件和实现文件中 ...
- LVM 逻辑卷管理
简介: LVM ( Logical Volume Manager ) 逻辑卷管理 一.创建 LV 1.首先在你的虚拟机上添加一块新的硬盘用来做实验. 2.安装 lvm : yum -y install ...
- NSTimer类的使用
转载于:http://www.cnblogs.com/wujian1360/archive/2011/09/05/2167992.html 创建一个 Timer + scheduledTimerWit ...
- GL_LINES & GL_LINE_STRIP & GL_LINE_LOOP
[GL_LINES] 独立的线段,下式中,p2与p3间没有连线. [GL_LINE_STRIP] 连续的线段,下式中, p2与p3会连成线段. [GL_LINE_LOOP] 参考:<计算机图形学 ...
- 欲望都市游戏设计 背景图层和UI图层的设计
- Professional C# 6 and .NET Core 1.0 - Chapter 42 ASP.NET Web API
本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处: -------------------------------------------------------- ...