Sequence(尺取)
Input
Output
Sample Input
2
10 15
5 1 3 5 10 7 4 9 2 8
11
1 2 3 4 5
Sample Output
2
3
题解:求连续子序列和大于等于s的最小长度。可以尺取,若sum<s,左指针右移,若sum>=s右指针左移,当sum<s时左指针继续右移,满足条件打擂台即可。
#include<cstring>
#include<cstdio>
#include<algorithm>
#define Inf 0x3f3f3f3f
#define ll long long
using namespace std;
ll str[];
int main()
{
ll i,j,m,n,t;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&m,&n);
for(i=;i<m;i++)
{
scanf("%lld",&str[i]);
}
ll sum=,cnt=,cur=,flag=,ans=Inf,count1=;
while(cur<m)
{
while(count1<m&&sum<=n)
{
sum+=str[count1++];
}
if(sum<n)
break;
flag=;
sum-=str[cur];
ans=min(ans,count1-cur);
cur++;
}
if(flag)
printf("%lld\n",ans);
else
puts("");
}
return ; }
Sequence(尺取)的更多相关文章
- NOJ 1072 The longest same color grid(尺取)
Problem 1072: The longest same color grid Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit in ...
- poj2566尺取变形
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- poj2100还是尺取
King George has recently decided that he would like to have a new design for the royal graveyard. Th ...
- POJ 2566 Bound Found 尺取 难度:1
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 1651 Accepted: 544 Spec ...
- poj3061 Subsequence(尺取)
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- POJ3061 Subsequence 尺取or二分
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- Sum of Consecutive Prime Numbers(素数打表+尺取)
Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...
- Bound Found(思维+尺取)
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】
任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...
随机推荐
- Ruby on Rails入门——macOS 下搭建Ruby Rails Web开发环境
这里只介绍具体的过程及遇到的问题和解决方案,有关概念性的知识请参考另一篇:Ruby Rails入门--windows下搭建Ruby Rails Web开发环境 macOS (我的版本是:10.12.3 ...
- [置顶]
C语言学习入门
编译文件:cc -c one.c two.c 生成.o目标文件 链接文件:cc one.o two.o 默认生成 a.out 执行文件 指定生成的可执行文件名 cc -o one one ...
- dojo chart生成函数
写了一个函数,就是通过传递参数,生成图表,代码如下: /** * created by LZUGIS * @param container * @param type * @param data * ...
- boost库做什么用呢?
1.C++标准库不是已经很全面了吗?Boost又不是界面库,它主要解决些什么问题呢?哪类问题?2.Boost的开发人员都是C++标准委员会的吧,为什么没把它列做标准库,有什么不完善的问题吗? 3.Bo ...
- 开发Wordpress主题时没有特色图片的功能
在自己开发Wordpress主题的时候,发现右下方没有了之前见到的特色图片(Featured Image)功能模块 1.找到后台右上方的显示选项模块,下拉之后启用即可 2.如果以上步骤找不到该选项,那 ...
- linux rm删除含有特殊符号目录或者文件
想要删除time$1.class,用rm time$1.class是不行的,可以用 rm time"$"1.class 删掉 假设Linux系统中有一个文件名叫“-polo”. ...
- Android的长度单位及屏幕分辨率
屏幕分辨率基础 1.术语和概念 术语 说明 备注 Screen size(屏幕尺寸) 指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸 摩托罗拉milestone手机 ...
- Hadoop2.7.1安装与配置
Hadoop2.7.1集群环境的搭建 s204.s205是我的两台服务器hostname,可以用你对应的ip或者hostname代替 工具/原料 jdk.ssh免登录 方法/步骤 1 首先去A ...
- 51nod 1012 最小公倍数LCM
输入2个正整数A,B,求A与B的最小公倍数. 收起 输入 2个数A,B,中间用空格隔开.(1<= A,B <= 10^9) 输出 输出A与B的最小公倍数. 输入样例 30 105 输出 ...
- 限制UITextfield的输入字符为50个字符
1.实现UITextfieldDelegate 2.在UITextfield的代理方法中判断添加字符还是删除字符,从而做不同的操作 #pragma mark-UITextfield的代理方法 - (B ...