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 ...
随机推荐
- java集合类-Set接口
Set集合 Set集合中的对象不按特定的方式排序,只是简单的把对象放入集合中,但是不能包含重复对象. Set集合由Set接口和Set接口的实现类组成,Set接口继承与于Collection接口 Set ...
- 第二章、URL与资源
1 URL统一资源定位符 URL 是浏览器寻找信息时所需的资源位置.通过 URL,人类和应用程序才能找到.使用并共享因特网上大量的数据资源.URL是作为URI的一个子集,URI是一类更通用的资源标识符 ...
- 在AspNetCore3.0中使用Autofac
1. 引入Nuget包 Autofac Autofac.Extensions.DependencyInjection 2. 修改Program.cs 将默认ServiceProviderFactory ...
- 为什么使用Spring Boot
原文:https://dzone.com/articles/why-springboot 作者:Siva Prasad Reddy Katamreddy 译者:Oopsguy 本文将介绍各种 Spri ...
- 多项式fft、ntt、fwt 总结
做了四五天的专题,但是并没有刷下多少题.可能一开始就对多项式这块十分困扰,很多细节理解不深. 最简单的形式就是直接两个多项式相乘,也就是多项式卷积,式子是$N^2$的.多项式算法的过程就是把卷积做一种 ...
- Maven的几种新建项目方式
1. 使用原型创建Maven的java工程 (1) 选择 JDK 的版本,勾选“使用原型创建”,选中 maven-archetype-quickstart,下一步. (2) 填写公司名,填写项目名,修 ...
- centos7中oracle数据库安装和卸载
参考: 完全命令行安装(验证可行):https://jingyan.baidu.com/article/90895e0f29c92164ec6b0bd1.html 存在疑问:是否需要jdk的配置(因为 ...
- sqli-labs通关记录
环境搭建:https://www.cnblogs.com/kagari/p/11910749.html 总体感受:sqli-labs还是只适合入门 在此基础上添加了一个flag数据库,库名flag,表 ...
- Python动态展示遗传算法求解TSP旅行商问题(转载)
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/jiang425776024/articl ...
- html文字两行后,就用省略号代替剩下的
html文字两行后,就用省略号代替剩下的 一.总结 一句话总结: 实现原理很简单,将box的高度设置为行高的两倍,超出之后隐藏,这样就只有两行了,然后再用after属性绝对定位在第二行后面加几个点 . ...