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 ...
随机推荐
- Java8_03_流
一.前言 这一节我们来看下Java8的又一新特性:流. 本节主要包括以下内容: 流的相关概念 使用流 收集器 二.流的相关概念 流允许你以声明性方式处理数据集合,可以将其看成遍历数据集的高级迭代器. ...
- 条款21:必须返回对象的时候,不要妄想使其返回reference
//先看看下面这个例子 class Rational{ public: Rational(int num, int denu) :numirator(num), denumirator(denu); ...
- [QT]问题记录-控件初始化导致程序异常关闭
qt新手,在设置 pushButton 的字体颜色时,出现软件异常闭,代码如下: 按钮的初始化在 ui->setupUi(this); 前边,会出现一下问题. 解决办法:将按钮的初始化在 u ...
- Thinking in Java 4th(Java编程思想第四版)文档、源码、习题答案
Thinking in Java 4th 中.英文两版pdf文档,书中源码及课后习题答案.链接:https://pan.baidu.com/s/1BKJdtgJ3s-_rN1OB4rpLTQ 密码:2 ...
- 1080. MOOC期终成绩 (25)
对于在中国大学MOOC(http://www.icourse163.org/)学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满 ...
- thunderbird 设置 邮件回复时内容在上方显示
1 . 编辑->属性 2.选择当前账户,在弹出窗体的右下角 选择 管理标示 ,在弹出窗中选择编辑 3.在弹出标识设置窗体中选择 编写&地址簿 选项卡选择 在引用内容之前回复
- MongoDB:MapReduce基础及实例
背景 MapReduce是个非常灵活和强大的数据聚合工具.它的好处是可以把一个聚合任务分解为多个小的任务,分配到多服务器上并行处理. MongoDB也提供了MapReduce,当然查询语肯定是Java ...
- homebrew的安装与使用
homebrew的安装:http://jingyan.baidu.com/article/fec7a1e5ec30341190b4e7e5.html 引用segfaultment上面的回答 没这个说法 ...
- gradle wrapper 简单使用
其实就是对于gradle 的一个包装,保证了项目版本的一致,同时减少配置 1. 生成wrapper // 使用gradle wrapper 命令 gradle wrapper 输出效果如下: [r ...
- 批量修改文件名后缀,例如:html修改成HTML
批量修改文件名后缀,例html修改成HTML 把文件后缀名html全部修改成HTML: 例:aa.html aa.HTML #!/bin/bash for file in `ls`;do mv $fi ...