题目传送门/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的更多相关文章

  1. POJ 3061 Subsequence 尺取

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14698   Accepted: 6205 Desc ...

  2. Subsequence (POJ - 3061)(尺取思想)

    Problem A sequence of N positive integers (10 < N < 100 000), each of them less than or equal ...

  3. Gym 100703I---Endeavor for perfection(尺取)

    题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...

  4. 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 ...

  5. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  6. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  7. poj2566尺取变形

    Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...

  8. poj2100还是尺取

    King George has recently decided that he would like to have a new design for the royal graveyard. Th ...

  9. hdu 6231 -- K-th Number(二分+尺取)

    题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...

随机推荐

  1. java集合类-List接口

    List接口包含List接口及List接口的所有实现类,List集合中的元素允许重复. List接口 List接口继承了Collection接口,包含Collection接口的所有方法,还定义了两个非 ...

  2. C语言学习笔记5-程序结构

    本系列文章由jadeshu编写,转载请注明出处.http://blog.csdn.net/jadeshu/article/details/50752148 作者:jadeshu   邮箱: jades ...

  3. Django基础之ModelForm

    1. form与model的终极结合 class BookForm(forms.ModelForm): class Meta: model = models.Book fields = "_ ...

  4. 用tecplot提取数据用于重构模型

    本方法还有诸多不完善的地方,转换代码转换格式之后还是需要自己手动分割txt文件,如果数据量太大,手动操作很是辛苦.现在只能得到点的数据,如何重构几何还是问题,UG貌似可以,欢迎交流. 首先在tecpl ...

  5. fiddler 基本知识(一)

    工作原理: fiddler,原理是在本机开启了一个http代理服务器,默认监听127.0.0.1:8888. 打开fiddler之后,会帮我们设置ie代理,虽然只设置了ie,但整个计算机都通过整个代理 ...

  6. go语言学习笔记之数组

    package main import ( "fmt" ) func main() { // Declare arrays var x[5] int //Assign value ...

  7. ubuntu下安装g++

    主要来自ubuntu中文社区http://www.ubuntu.org.cn/support/documentation/doc/VMware 首选,确认你已经安装了build-essential程序 ...

  8. (八)爬虫之js调试(登陆知乎)

    上次爬取网易云音乐,折腾js调试了好久,难受....今天继续练练手,研究下知乎登陆,让痛苦更猛烈些. 1.简单分析 很容易就发现登陆的url=“https://www.zhihu.com/api/v3 ...

  9. 使用python获取微医数据

    用到的包: BeautifulSoup pymysql requests json 碰到的问题: 1.医生查询分页数据不能超过38页,超过无法返回数据 2.某些字段对应的html元素包含一些无效的cl ...

  10. 文件上传使用FileUpload组件进行代码实现

    使用FileUpload组件进行代码实现 实现步骤 1. 获取解析器工厂: DiskFileItemFactory 2. 获取解析器对象: ServletFileUpload 3. 解析request ...