题目: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的更多相关文章

  1. poj3061 Subsequence(尺取法)

    https://vjudge.net/problem/POJ-3061 尺取发,s和t不断推进的算法.因为每一轮s都推进1所以复杂度为O(n) #include<iostream> #in ...

  2. poj3061 Subsequence(尺取)

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  3. POJ3061 Subsequence 尺取or二分

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  4. poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)

    这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...

  5. POJ3061 Subsequence

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16520   Accepted: 7008 Desc ...

  6. poj3061 Subsequence【尺取法】

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  7. poj3061 Subsequence ,尺取法

    A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, a ...

  8. POJ3061——Subsequence(尺取法)

    Subsequence POJ - 3061 给定长度为n的数列整数a0,a1,a2-an-1以及整数S.求出总和不小于S的连续子序列的长度的最小值,如果解不存在输出0. 反复推进区间的开头和末尾,来 ...

  9. [POJ3061]Subsequence(二分,前缀和)

    题目链接:http://poj.org/problem?id=3061 题意:给一个长为n的数列和整数s,求一个连续的子序列,使得这个子序列长度最短并且不小于这个整数s. 统计[1~i]的子序列和su ...

随机推荐

  1. Mysql Docker Container Command

    Hello, in my docker-compose file I have the following: db: image: mysql command: mysqld --character- ...

  2. Android中SharePreferences的简单实现

    Android中提供SharePreferences这种轻量级的数据存储模式,这种模式能够存储少量数据,并能为自身和其他应用提供数据接口.相对于其他数据存储方式,SharePreferences更加轻 ...

  3. Vim配置:在win10下用vim编译运行C/C++(异步插件管理,一键运行)

    为什么用Vim 重新调配vim,追求尽量简单些. 安装 官网下载 PC: MS-DOS and MS-Windows下的 For modern MS-Windows systems (starting ...

  4. 【airflow实战系列】 基于 python 的调度和监控工作流的平台

    简介 airflow 是一个使用python语言编写的data pipeline调度和监控工作流的平台.Airflow被Airbnb内部用来创建.监控和调整数据管道.任何工作流都可以在这个使用Pyth ...

  5. Eclipse debug 的 drop to frame 的技巧

    前些天和同事交流调试技巧时,知道了 Eclipse debug 时有个 drop to frame 的技巧.这是我以前不知道的,自己又查了一下这个功能的含义.官方的解释是: Select the Dr ...

  6. Spring3开发(一)

    1 Ioc是什么? Ioc:Inversion of Control,控制反转,控制权从应用程序转移到框架(如Ioc容器),是框架的共有特性. 1.1 为什么需要IoC容器?IoC容器是如何演变的? ...

  7. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException/com.atomikos.datasource.ResourceException异常解决

    tomcat+mysql部署,每天早晨第一次访问web项目,出现mysql的连接timeout异常:com.mysql.jdbc.exceptions.jdbc4.CommunicationsExce ...

  8. 并发编程和MySQL总结

    1️⃣  并发编程主要内容: 操作系统工作原理介绍.线程.进程演化史.特点.区别.互斥锁.信号.事件.join.GIL.进程间通信.管道.队列. 生产者消费者模型.异步模型.IO多路复用模型.sele ...

  9. 网页静态化—redis | freemarker

    1.   学习计划 1.商品详情页面展示,动态展示 jsp + redis 2.使用freemarker实现网页静态化 3.ActiveMq同步生成静态网页 两个方案对比,方案一依赖web容器,red ...

  10. Android开发实战之简单音乐播放器

    最近开始学习音频相关.所以,很想自己做一个音乐播放器,于是,花了一天学习,将播放器的基本功能实现了出来.我觉得学习知识点还是蛮多的,所以写篇博客总结一下关于一个音乐播放器实现的逻辑.希望这篇博文对你的 ...