POJ-3061】的更多相关文章

题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点慢. 二分枚举序列长度,如果可行,向左找小的,否则向右找大的. 前缀和预处理之后,可以O(1)内求和. #include "cstdio" #include "cstring" ],n,s,a,T; bool check(int x) { int l,r; ;i+x-&…
题目连接 http://poj.org/problem?id=3061 Subsequence 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 len…
[题目链接] http://poj.org/problem?id=3061 [题目大意] 给出S和一个长度为n的数列,问最短大于等于S的子区间的长度. [题解] 利用双指针获取每一个恰好大于等于S的子区间,更新答案即可. [代码] #include <cstdio> int T,a[100005]; int main(){ scanf("%d",&T); while(T--){ int n,S,s,h,t,ans; scanf("%d%d",&a…
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…
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]+--…
地址 http://poj.org/problem?id=3061 解法1 使用双指针 由于序列是连续正数 使用l r 表示选择的子序列的起始 每当和小于要求的时候 我们向右侧扩展 增大序列和 每当和大于等于要求的时候 我们将子序列左边的数字剔除 看能是在减少长度情况下 还能保持子序列和满足要求 这样在指定起点下的满足要求的最短子序列和都会被记录 然后在比较出最短长度的子序列 如图 代码 #include <iostream> #include <vector> #include…
传送门:Problem 3061 https://www.cnblogs.com/violet-acmer/p/9793209.html 马上就要去上课了,先献上二分AC代码,其余的有空再补 题意: 给定长度为 n 的整数数列 a[0,1,2,........,n]以及整数 S. 求出总和不小于 S 的连续子序列的长度的最小值. 如果解不存在,则输出 0. 题解: 1.二分 由于所有的元素都大于 0 ,所以数组a[ ] 的前缀和sum[ ]为递增的序列,满足二分的条件. 首先确定子序列的起点为s…
题意 $ 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 题目描述 给定长度为n的数列整数以及整数S.求出总和不小于S的连续子序列的长度的最小值.如果解不存在,则输出0. 思路 O(nlogn)算法 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; int main() { int T; sca…
  和最短序列 题目大意:找出一个序列中比至少和S相等的最短子序列(连续的) 本来这道题可以二分法来做复杂度O(NlogN),也可以用一个类似于游标卡尺的方法O(N)来做 先来讲游标卡尺法: 因为子序列是连续的,所以我们只用维护这个序列的开头和结尾就行了,保证这个序列的和一定要大于S,如果从头到尾的和都没S大那就直接输出0就好,ans初始化为n+1 #include <iostream> #include <functional> #include <algorithm>…