Subsequence
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10882   Accepted: 4498

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 of the sequence, the sum
of which is greater than or equal to S.

Input

The first line is the number of test cases. For each test case the program has to read the numbers N and S, separated by an interval, from the first line. The numbers of the sequence are given in the second line of the test case, separated by intervals. The
input will finish with the end of file.

Output

For each the case the program has to print the result on separate line of the output file.if no answer, print 0.

Sample Input

2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5

Sample Output

2
3

Source

Southeastern Europe 2006

简直就是超时专题,还是自己太傻了,想着暴力可以的,

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int num[100000+10];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,ans;
scanf("%d%d",&n,&ans);
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
int l=0,r=0,minn=0x3f3f3f,sum=0;
bool f=false;
while(r<n)
{
sum+=num[r++];
while(sum>=ans)
{
f=true;
minn=min(minn,r-l);
sum-=num[l++];
}
}
if(f)
printf("%d\n",minn);
else
printf("0\n");
}
return 0;
}

poj--3061--Subsequence(贪心)的更多相关文章

  1. poj 3061 Subsequence

    题目连接 http://poj.org/problem?id=3061 Subsequence Description A sequence of N positive integers (10 &l ...

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

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

  3. POJ 3061 Subsequence(Two Pointers)

    [题目链接] http://poj.org/problem?id=3061 [题目大意] 给出S和一个长度为n的数列,问最短大于等于S的子区间的长度. [题解] 利用双指针获取每一个恰好大于等于S的子 ...

  4. POJ 3061 Subsequence 二分或者尺取法

    http://poj.org/problem?id=3061 题目大意: 给定长度为n的整列整数a[0],a[1],--a[n-1],以及整数S,求出总和不小于S的连续子序列的长度的最小值. 思路: ...

  5. poj 3061 Subsequence 二分 前缀和 双指针

    地址 http://poj.org/problem?id=3061 解法1 使用双指针 由于序列是连续正数 使用l r 表示选择的子序列的起始 每当和小于要求的时候 我们向右侧扩展 增大序列和 每当和 ...

  6. POJ 3061 Subsequence(尺取法)

    题目链接: 传送门 Subsequence Time Limit: 1000MS     Memory Limit: 65536K 题目描述 给定长度为n的数列整数以及整数S.求出总和不小于S的连续子 ...

  7. Poj 3061 Subsequence(二分+前缀和)

    Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12333 Accepted: 5178 Descript ...

  8. [ACM] POJ 3061 Subsequence (仿真足)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8403   Accepted: 3264 Descr ...

  9. POJ 3061 Subsequence 尺取法 POJ 3320 Jessica's Reading Problem map+set+尺取法

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 5896 Desc ...

  10. POJ 3061 Subsequence 尺取法,一个屌屌的O(n)算法

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9050   Accepted: 3604 Descr ...

随机推荐

  1. 更改计算机名后DB2不能启动的解决方法

    1.找到以下位置目录下相应的文件db2nodes.cfg C:\Documents and Settings\All Users\Application Data\IBM\DB2\DB2COPY1\D ...

  2. Python 之数据类型

    # Numbers(数字) # int(有符号整型) # long(长整型[也可以代表八进制和十六进制]) # float(浮点型) # complex(复数) # String(字符串) # Lis ...

  3. MFC CAD控制权问题

    begineditorcommand(); 隐藏对话框  把控制权交给CAD completeeditorcommand(); 完成交互返回到应用程序 canceleditorcommand CAD被 ...

  4. How To: set udev rule for setting the disk permission on ASM disks when using multipath on Linux 6.x

    在RHEL6.4上安装11gR2的RAC时,使用了MULTIPATH来聚合绑定多路径的磁盘,并且修改磁盘的权限,赋予grid:asmadmin用户和组. 此时,在安装时可以发现磁盘,日志如下 INFO ...

  5. UID中RUID、EUID和SUID的区别

    看UNIX相关的书时经常能遇到这几个概念,但一直没有好好去理清这几个概念,以致对这几个概念一直一知半解.今天好好区分了一下这几个概念并总结如下.说白了这几个UID引出都是为了系统的权限管理. 下面分别 ...

  6. Unity jointmoto

    jointmoto是模拟电机的,他的参数包括了最高车速和最大扭矩 扭矩总是正数,而目标车速决定了方向

  7. SSH免密登录的错误

    为了避免每次在测试环境启动hadoop都需要输入密码, 使用免密操作 ssh-keygen,然后一直按enter键 接着需要输入root密码, 输入root密码后一直报错,密码不正确, permiss ...

  8. TCP/IP UDP 协议首部及数据进入协议栈封装的过程

    数据的封装 UDP 封装 TCP 封装 IP 封装 检验和算法 当应用程序用TCP传送数据时,数据被传送入协议栈中,然后逐一通过每一层直到被当作一串比特流送入网络 注: UDP数据TCP数据基本一致. ...

  9. svn 使用TortoiseSVN server搭建本地SVN服务器

    使用TortoiseSVN server搭建本地SVN服务器

  10. js调用ro的webservice

    Enabling JavaScript Access on the Server Drop the JavaScriptHttpDispatcher component onto the server ...