Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18145   Accepted: 7751 Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) ar…
Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 5896 Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) ar…
转自博客:http://blog.chinaunix.net/uid-24922718-id-4848418.html 尺取法就是两个指针表示区间[l,r]的开始与结束 然后根据题目来将端点移动,是一种十分有效的做法.适合连续区间的问题 poj3061 给定长度为n的数列整数a0,a1,a2,a3 ..... an-1以及整数S.求出综合不小于S的连续子序列的长度的最小值.如果解不存在,则输出0. 这里我们拿第一组测试数据举例子,即 n=10, S = 15, a = {5,1,3,5,10,7…
Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9050   Accepted: 3604 Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are…
题意 $ T $ 组数据,每组数据给一个长度 $ N $ 的序列,要求一段连续的子序列的和大于 $ S $,问子序列最小长度为多少. 输入样例 2 10 15 5 1 3 5 10 7 4 9 2 8 5 11 1 2 3 4 5 输出样例 2 3 解析 我们很容易发现对于这题我们可以二分答案,先找出一个初始长度,判断是否存在合法序列,如果存在缩小长度,如果不存在加长长度. 时间复杂度 $ O(nlogn) $ 代码 #include<cstdio> #include<algorithm…
Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14698   Accepted: 6205 Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) ar…
http://poj.org/problem?id=3061 题目大意: 给定长度为n的整列整数a[0],a[1],--a[n-1],以及整数S,求出总和不小于S的连续子序列的长度的最小值. 思路: 方法一: 首先求出各项的和sum[i],这样可以在O(1)的时间内算出区间上的总和,这样,枚举每一个起点i,然后二分搜索出结果大于sum[i]+tot的最小下标.(tot是题目中的S) 总的时间为O(nlogn) 方法二: 设以a[s]开始的总和最初大于S时的连续子序列为a[s]+a[s+1]+--…
题目链接 Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive eleme…
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements o…
<题目链接> 题目大意: 给你一段长度为n的整数序列,并且给出一个整数S,问你这段序列中区间之和大于等于S的最短区间长度是多少. 解题分析:本题可以用二分答案做,先求出前缀和,然后枚举区间长度,然后再判断其是否合法即可,复杂度$O(nlog(n))$.同时,尺取法也是一个不错的选择,通过不断的移动区间的头.尾指针来寻求答案,复杂度为 $O(n)$. 尺取法: #include <cstdio> #include <cstring> #include <algori…