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 ...
随机推荐
- Struts05---动态查询
01.在上面案例的login.jsp页面新增 <%-- 2.动态方法的调用 前提是在 struts.xml文件中开启 不推荐! --%> <a href="user/use ...
- LeetCode OJ:Rotate Image(旋转图片)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- 条款21:必须返回对象的时候,不要妄想使其返回reference
//先看看下面这个例子 class Rational{ public: Rational(int num, int denu) :numirator(num), denumirator(denu); ...
- Arcgis for Androd API开发系列教程(一)——地图显示与GPS定位
序:最近呢,工作鸭梨不是怎么大,对于自己爱折腾的想法又冒出了水面,开始自己的android开发的学习之旅.但是呢,本人是做GIS的,所以呢,就打算从这方面入手看看,是不是有什么比较好玩的玩意呢,这才导 ...
- golang:bson.ObjectId与string转化
网上资料不好搜,记下来:两个变量:id bson.ObjectIdstr string bson.ObjectId—>string id.Hex() string—>bson.Object ...
- phpcms URL
http://www.jb51.net/cms/112109.html 静态URL生成规则 http://v9.help.phpcms.cn/html/2010/database_1228/107.h ...
- rebar自定义template
在开发过程中rebar自带模板建立项目,或多或少不能满足自己的开发需求.本人又是那种懒人,所以就要想办法偷懒.查看了priv模板 打造适合自己的项目模板.下面我简单的介绍整个模板的打造过程. 准备过程 ...
- CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)
As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initi ...
- tensorflow中常用激活函数和损失函数
激活函数 各激活函数曲线对比 常用激活函数: tf.sigmoid() tf.tanh() tf.nn.relu() tf.nn.softplus() tf.nn.softmax() tf.nn.dr ...
- Activiti工作流学习之流程图应用详解
Activiti工作流学习之流程图应用详解 1.目的 了解Activiti工作流是怎样应用流程图的. 2.环境准备2.1.相关软件及版本 jdk版本:Jdk1.7及以上 IDE:eclipse ...