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 ...
随机推荐
- IE6&IE7 bug
IE6 Bugs 1 .不支持用样式设置 <abbr> 元素 2 .不支持以连字符和下划线开头的 class 和 ID 名 3 . <select> 元素总是出现在堆叠最上面, ...
- 抓https包
一.charles抓https 1.打开charles,打开Help--SSL Proxy--Install Charles Root Certificate,charles安装证书,傻瓜式安装即可 ...
- java如何填写简历?(干货篇)
化身孤岛的鲸不才 - 十三夜之月 一份优秀的简历不一定能帮你找到一份满意的工作,但能大大提升你的面试机会. 不容否认,简历是对你的能力.教育和经历的一份简要信息概述. 简历中应该突出你最核心的 ...
- 使用Hydra通过ssh破解密码
Hydra是非常高效的网络登录破解工具,它可以对多种服务程序执行暴力破解(SSH.VNC等等). 防止这种攻击其实很容易,方法很多.以SSH为例: Ubuntu:使用Port Knocking隐藏SS ...
- "==" 与 "is"的区别
Is there a difference between `==` and `is` in Python? "=="是比较内容相当;"is"是比较对象的id是 ...
- iOS6和iOS7代码的适配(6) —— NSLocalizedString
我们的应用都是需要国际化的,字符串也是重要的一环.一般来说,我们是通过一个string资源文件来实现这个目的的,我们需要支持几种语言,就把这个文件本地化多少次.代码中需要用NSLocalizedStr ...
- LG2120 [ZJOI2007]仓库建设
题意 L公司有N个工厂,由高到底分布在一座山上. 工厂1在山顶,工厂N在山脚. 由于这座山处于高原内陆地区(干燥少雨),L公司一般把产品直接堆放在露天,以节省费用. 突然有一天,L公司的总裁L先生接到 ...
- webpack中多模块依赖
多模块依赖 刚才的例子,我们仅仅是跑通了webpack通过entry.js入口文件进行打包的例子.下面我们就来看一下它是否真的支持CommonJs和AMD两种模块机制呢?下面我们新建多几个js文件吧! ...
- c#代碼小集
一.字符串[Uri]轉換出RouteData private RouteData UriToRouteData(Uri uri) { var query = uri.Query; ) { query ...
- (转)android - anim translate中 fromXDelta、toXDelta、fromYDelta、toXDelta属性
2012-03-23 15:51 16144人阅读 评论(5) 收藏 举报 android <set xmlns:android="http://schemas.android.com ...