poi 3061 尺取例题1
题目传送门/res tp poj
白书题
尺取法例题
#include<iostream>
#include<algorithm>
using namespace std;
const int L = 100100;
typedef long long ll;
ll a[L],sum[L],s;
int n,T;
int getans(){
int ans = n+1;
int fr=1,re=1;
while(fr<=re){
while(sum[re]-sum[fr-1] <s){
re++;if(re == n+1)return ans;
}
while(sum[re]-sum[fr-1] >=s){
ans = min(ans,re-fr+1);fr++;
}
}
return ans;
}
int main(){
cin>>T;
while(T--){
cin>>n>>s;
for(int i = 1;i<=n;++i) cin>>a[i];
for(int i = 1;i<=n;++i)sum[i]=sum[i-1]+a[i];
int ans = getans();
if(ans == n+1) cout<<0<<endl;
else cout<<ans<<endl;
}
}
poi 3061 尺取例题1的更多相关文章
- POJ 3061 Subsequence 尺取
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14698 Accepted: 6205 Desc ...
- Subsequence (POJ - 3061)(尺取思想)
Problem A sequence of N positive integers (10 < N < 100 000), each of them less than or equal ...
- Gym 100703I---Endeavor for perfection(尺取)
题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...
- 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 ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- 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 ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
随机推荐
- redis之持久化RDB与AOF
redis数据持久化 Redis是一种内存型数据库,一旦服务器进程退出,数据库的数据就会丢失,为了解决这个问题,Redis提供了两种持久化的方案,将内存中的数据保存到磁盘中,避免数据的丢失. RDB持 ...
- UVALive 4976 Defense Lines ——(LIS变形)
题意:给出序列,能够从这序列中删去连续的一段,问剩下的序列中的最长的严格上升子串的长度是多少. 这题颇有点LIS的味道.因为具体做法就是维护一个单调的集合,然后xjbg一下即可.具体的见代码吧: #i ...
- hive 调优(一)coding调优
本人认为hive是很好的工具,目前支持mr,tez,spark执行引擎,有些大公司原来封装的sparksql,开发py脚本,但是目前hive支持spark引擎(不是很稳定,建议Tez先),所以离线还是 ...
- SpringBoot2.0 Actuator 监控参数说明
主要内容更 监控参数说明 Maven坐标 <dependency> <groupId>org.springframework.boot</groupId> < ...
- LayerDrawable
层图形对象,包含一个Drawable数组,然后按照数组对应的顺序来绘制他们,索引 值最大的Drawable会被绘制在最上层!虽然这些Drawable会有交叉或者重叠的区域,但 他们位于不同的层,所以并 ...
- 006-log-logback,slf4j+logback
一.概述 Logback作为流行的log4j项目的继承者.它是由log4j的创始人Ceki Gulcu设计的.它是建立在上十年优质日志系统设计经验之上而产生的产品,即logback,它比所有现有的日志 ...
- ffprobe读取音视频元数据信息,json格式输出
命令格式: ffprobe -v quiet -show_format -show_streams -print_format json F:\temp\test1566606924822.wav 输 ...
- delphi中Treeview的使用介绍
今天重点学习了TreeView的使用方法,基本的已经写了,现在主要想说的是如何显示数据库的资料,今天只是做了个较简单的例子,一个父节点下显示数据库中某个field的值.代码如下: procedure ...
- [C++/JavaScript]数据结构:栈和数列>案例引入(数制的转换)
1 案例1:数制的转换 1.1 背景与原理 1.2 编程复现 (JavaScript版 复现) function convert(value, d){ stack = []; // 栈 result ...
- nginx服务报错解决
403禁止访问解决 . 重要:修改配置文件使用虚拟机,否则怎么配置都不生效,添加如下用户 [root@host---- html]# ll /etc/nginx/nginx.conf -rw-r--r ...