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 ...
随机推荐
- 【线性代数】6-3:微分方程的应用(Applications to Differential Equations)
title: [线性代数]6-3:微分方程的应用(Applications to Differential Equations) categories: Mathematic Linear Algeb ...
- JMeter压力测试及并发量计算-1
一.JMeter的安装(Linux) 1. 下载JMeter:这个就不细说了,直接去(http://jmeter.apache.org/download_jmeter.cgi)下载. 2. 解压:ta ...
- Java 线程概述
1 进程与线程基本概念 1.1 进程:执行中的程序 每个进程都有独立的代码和数据空间(进程上下文),进程空间切换会有较大的开销,一个进程包含1-n个线程.进程是资源分配的最小单位. 1.2 线程:进程 ...
- idea 拉取git新分支
前面的话: 一不小心,删除了dev的分支,没办法.头头重新克隆了下,但是发现idea的右下角并没有啊,我记得之前遇到过一次 但还是忘记如何操作了,在这记录下,省的下次还得去百度 选中项目-git-fe ...
- Wamp win10 1077error
检查日志发现了1077错误 State of services: The service 'wampapache64' is NOT started EXIT error code:1077 He ...
- CPU、io、mem之间的关系
https://blog.csdn.net/weixin_38250126/article/details/83412749 https://blog.csdn.net/joeyon1985/arti ...
- Mac Mysql 5.6.4修改初始化密码
Mac Mysql 修改初始化密码 第一步: 点击系统偏好设置->最下边点MySQL,在弹出页面中,关闭服务 第二步:进入终端输入:cd /usr/local/mysql/bin/回车后 登 ...
- Zynq_soc学习
Zynq_soc学习 SFP高速串行通信得搞来看看 最小系统 PL端时钟配置: 配置DDR控制器,主要是添加DDR正确的型号 外设电平接口配置: BANK0:LVCMOS3.3 BANK1:LVCMO ...
- [转][echarts]地图轮播
代码片断: 来自:https://blog.csdn.net/qq_36947128/article/details/90899564 function Play(){ chart.dispatchA ...
- <JavaScript> 稳妥构造函数模式与工厂模式的区别
稳妥构造函数模式的代码应该是这样的: function Person(name, age, job) { var o = new Object(); // private members var na ...