【二分】Subsequence
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 15908 | Accepted: 6727 |
Description
Input
Output
Sample Input
2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5
Sample Output
2
3
Source
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
#define LL long long
const int MAXN=1000001;
const int INF=999999;
const int mod=999993;
int N,S;
int a[1000001];
int tmp; bool check(int k){
long long sum=0;
for(int i=1;i<=k;i++){
sum+=a[i];
}
if(sum>=S) return true;
for(int i=2;i+k-1<=N;i++){
sum-=a[i-1];sum+=a[i+k-1];
if(sum>=S) return true;
}
return false;
} int main(){
int T=read();
while(T--){
N=read(),S=read();long long k=0;
for(int i=1;i<=N;i++) a[i]=read(),k+=a[i];
if(k<S) {printf("0\n");continue;}
int l=1,r=N;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) r=mid-1;
else l=mid+1;
}
printf("%d\n",l);
}
}
【二分】Subsequence的更多相关文章
- Subsequence poj 3061 二分(nlog n)或尺取法(n)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9236 Accepted: 3701 Descr ...
- Poj 3061 Subsequence(二分+前缀和)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12333 Accepted: 5178 Descript ...
- 【二分答案nlogn/标解O(n)】【UVA1121】Subsequence
A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, a ...
- Subsequence(暴力+二分)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10875 Accepted: 4493 Desc ...
- POJ3061 Subsequence 尺取or二分
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- CSU1553 Good subsequence —— 二分 + RMQ/线段树
题目链接: http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1553 Description Give you a sequence of n n ...
- 题解报告:poj 3061 Subsequence(前缀+二分or尺取法)
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- Intel Code Challenge Final Round D. Dense Subsequence 二分思想
D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CSU 1553 Good subsequence(RMQ问题 + 二分)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1553 Description Give you a sequence of n nu ...
随机推荐
- [Unity]游戏Inside中的Chromatic Aberration效果学习
Chromatic Aberration效果指的是模拟摄像机的拍摄瑕疵导致rgb三个通道的颜色发生了偏移,如 传统的Chromatic Aberration实现往往是基于一个后处理,将rgb采样的坐标 ...
- 一个简单插件this传值的跟踪
<!DOCUTYPE html> <html> <head> <meta charset="UTF-8"> <script s ...
- SpringBoot工程目录配置
Spring Boot建议的目录结果如下: root package结构:com.example.myproject com +- example +- myproject +- Applicat ...
- arping详解
arping干嘛用的? arping主要干的活就是查看ip的MAC地址及IP占用的问题. 参数 -0:指定源地址为0.0.0.0,这个一般是在我们刚刚安装好系统,电脑还没配置好IP的时候 -a:Aud ...
- linux编程之文件操作
在linux下用文件描述符来表示设备文件盒普通文件,文件描述符是一个整型的数据,所有对文件的操作都是通过文件描述符来实现的. 文件描述符是文件系统中连接用户空间和内核空间的枢纽,当我们打开一个或者创建 ...
- 网络知识===wireshark抓包出现“TCP segment of a reassembled PDU”的解释(载)
网上胡说八道,众说风云,感觉这篇还算靠谱点. 原文链接:http://blog.csdn.net/dog250/article/details/51809566 为什么大家看到这个以后总是会往MSS, ...
- nginx源码分析--使用GDB调试(strace、 pstack )
nginx源码分析--使用GDB调试(strace. pstack ) http://blog.csdn.net/scdxmoe/article/details/49070577
- python并发模块之concurrent.futures(二)
python并发模块之concurrent.futures(二) 上次我们简单的了解下,模块的一些基本方法和用法,这里我们进一步对concurrent.futures做一个了解和拓展.上次的内容点这. ...
- 【Educational Codeforces Round20】
这场edu有点简单…… 所以题目可能也有点奇奇怪怪的. A.随意构造一下,可以发现只有当填满都不行时才可能无解. #include<bits/stdc++.h> using namespa ...
- 辨别苹果数据线真伪 苹果计算器 Dashboard 知识
辨别苹果数据线真伪 苹果计算器 Dashboard 知识 苹果数据线真伪的最简单的辨别: 线质柔软 用数据线连接适配器(苹果自带的适配器)充电 连接手机 如果该手机数据线是假的, 在手机上会提示”该 ...