input

n s 10<=n<=100000,s<1e9

a1 a2 ... an     ai<=10000

output

大于s的最短子序列和的长度,没有输出0

 #include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#define MAX 100000 using namespace std;
int n,s,a[MAX+];
int main()
{
freopen("/home/user/桌面/in","r",stdin);
while(scanf("%d%d",&n,&s)==)
{
int ans=0x7fffffff;
scanf("%d",&a[]);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
a[i]+=a[i-];
}
int p=;
for(int i=;i<n;i++)
{
if(a[i]-s>) p=lower_bound(&a[p],a+i,a[i]-s)-a;
if(p>) ans=min(ans,i-p+);
}
/* for(int i=0,j=0;i<n;i++)
{
if(a[j]>a[i]-s) continue;
while(a[j]<a[i]-s) j++;
ans=min(ans,i-j+1);
}*/
a[n-]>=s?printf("%d\n",ans):puts("");
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return ;
}

UVALive 2678 大于s的最短子序列和的更多相关文章

  1. POJ - 3061 Subsequence(连续子序列和>=s的最短子序列长度)

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

  2. LeetCode Minimum Size Subarray Sum (最短子序列和)

    题意:给一个序列,找出其中一个连续子序列,其和大于s但是所含元素最少.返回其长度.0代表整个序列之和均小于s. 思路:O(n)的方法容易想.就是扫一遍,当子序列和大于s时就一直删减子序列前面的一个元素 ...

  3. UVALive 2678 利用序列的前缀来减少时间复杂度

    题意很简单,在一串正整数序列中找一个连续的子序列使该序列和大于等于一个已知量S,但要求序列长度最短,通常喜欢暴力枚举 这个题目跟大白书之前的一个题目很像,在数列A中 求 Ai-Aj最大 并且 i< ...

  4. LA2678最短子序列

    题意:       给你一个正整数序列,问你在里面找到一个最短的子序列,要求子序列的和大于等于k,输出序列长度. 思路:       这个序列的每个数字都是正整数,那么就比较好想了,我们可以直接枚举终 ...

  5. [UVALive 2678] Subsequence

    图片加载可能有点慢,请跳过题面先看题解,谢谢 在切水题的道路上狂奔,一发不可收拾... 这道题好像不用写什么题解吧,吐个槽什么的算了 一眼题,大佬们都不屑于做,只有我这种弱菜才来写这种题目玩儿 记个前 ...

  6. UVALive - 2678 二分/尺取

    题意:求最小的长度L满足该长度上的元素和大于等于S 最近dp做多了总有一种能用dp解决一切的错觉 二分长度解决 #include<iostream> #include<algorit ...

  7. 209 Minimum Size Subarray Sum 大于给定和最短子数组

    给定一个含有 n 个正整数的数组和一个正整数 s , 找到一个最小的连续子数组的长度,使得这个子数组的数字和 ≥  s .如果不存在符合条件的子数组,返回 0.举个例子,给定数组 [2,3,1,2,4 ...

  8. nyoj133_子序列_离散化_尺取法

    子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 ...

  9. 最长上升子序列(logN算法)

    例如:1 7 3 5 9 4 8 一个序列,比如说a[]={1,7,3,5,9,4,8},找出它的最长上升子序列的个数,很明显是4个,可以是{1,3,5,9},{1,3,5,8}或者{1,3,4,8} ...

随机推荐

  1. mysql解决中文乱码问题

    安装文件 my.ini default-character-set=gbk 安装文件 db.opt default-character-set=gbkdefault-collation=gbk_chi ...

  2. 安卓访问webAPI,并取回数据

    前言 安卓自从4.0以后,所有的网络访问都需要异步进程操作.其自带的异步类有AsyncTask,Handler,以及可以声明Thread等等.涉及到多进程,必须要提到一个问题,线程与线程之间不能直接进 ...

  3. sql新建数据库表,及添加多个主键

    create table tb_Modules(module_Id int identity(1,1) primary key,  (自增)model_Name varchar(50) not nul ...

  4. linux之sed命令

    原命令行: sudo sed -i 's/${storm.home}\/logs\/var\/log\/storm/g' /usr/share/storm/log4j/storm.log.proper ...

  5. delphi edit 中undo 和clearundo 复制粘贴等总结

    edit 和memo都有undo功能, Undo:恢复到改动前. ClearUndo:撤销掉Undo缓冲区的内容,则将无法恢复到改动前的 从该文本框的撤销缓冲区中清除关于最近操作的信息,根据应用 程序 ...

  6. Gentoo:Xorg:Failed to load module "……" 问题

    错误描述: 安装完xorg-server后,startx启动桌面环境,出现缺少模块错误. Xorg:Failed to load module "--" 查看log: cat /v ...

  7. iOS 计算两个坐标之间的距离

    //第一个坐标 CLLocation *before=[[CLLocation alloc] initWithLatitude:29.553968 longitude:106.538872]; //第 ...

  8. mysql教程

    mysql教程 2016年5月14日 0:09 1.查看mysql帮助信息 C:\Users\zhangcunli>mysql --help mysql  Ver 14.14 Distrib 5 ...

  9. android中对Bitmap图片设置任意角为圆角

    http://blog.csdn.net/l448288137/article/details/48276681 最近项目开发中使用到了圆角图片,网上找到的圆角图片控件大多比较死板,只可以全圆角.其中 ...

  10. C++设计模式-Iterator迭代器模式

    ref: http://www.cnblogs.com/onlycxue/archive/2013/12/25/3490738.html