A - Subsequence (算法 二分 )
of the sequence, the sum of which is greater than or equal to S.
separated by intervals. The input will finish with the end of file.
2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5
2
3
#include<stdio.h>#include<algorithm>#define
MAX 100000using
namespace
std;int
main(){int
u;int
sum[MAX+22];int
ans;int
n,s;scanf("%d",&u);while(u--){scanf("%d
%d",&n,&s);scanf("%d",&sum[0]);
//注意这个地方
for(int
i=1;
i<n; i++){scanf("%d",&sum[i]);sum[i]+=sum[i-1];
} if(sum[n-1]<s)
{ printf("0\n");
continue;
} ans =n; int
pos; for(int
i=n-1;
i>=0;
i--) { if(sum[i]<s)
break;
pos=upper_bound(sum,sum+n,sum[i]-s)-sum; ans=min(ans,i-pos+1);
} printf("%d\n",ans);
} return
0;}
A - Subsequence (算法 二分 )的更多相关文章
- 训练指南 UVA- 11865(有向最小生成树 + 朱刘算法 + 二分)
layout: post title: 训练指南 UVA- 11865(有向最小生成树 + 朱刘算法 + 二分) author: "luowentaoaa" catalog: tr ...
- 南理第八届校赛同步赛-F sequence//贪心算法&二分查找优化
题目大意:求一个序列中不严格单调递增的子序列的最小数目(子序列之间没有交叉). 这题证明贪心法可行的时候,可以发现和求最长递减子序列的长度是同一个方法,只是思考的角度不同,具体证明并不是很清楚,这里就 ...
- hdu2063 匈牙利算法 二分最大匹配模版题
过山车 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java class na ...
- uva11865 朱刘算法+二分
这题说的需要最多花费cost元来搭建一个比赛网络,网络中有n台机器,编号为0 - n-1其中机器0 为服务器,给了n条线有向的和他们的花费以及带宽 计算,使得n台连接在一起,最大化网络中的最小带宽, ...
- UVA-11865 Stream My Contest (朱-刘 算法+二分)
题目大意:有一张n个顶点,m条边的有向图,根节点为0.每条边有两个权值,一个是费用c,一个是长度b.问在总费用不超过cost的情况下选出若干条边,使得n个点连通时的边的最短长度的最大值是多少. 题目分 ...
- 莫队算法/二分查找 FZU 2072 Count
题目传送门 题意:问区间内x的出现的次数分析:莫队算法:用一个cnt记录x的次数就可以了.还有二分查找的方法 代码: #include <cstdio> #include <algo ...
- #C++初学记录(贪心算法#二分查找)
D - Aggressive cows 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 < ...
- LA 2678 Subsequence(二分查找)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- Java-数据结构与算法-二分查找法
1.二分查找法思路:不断缩小范围,直到low <= high 2.代码: package Test; import java.util.Arrays; public class BinarySe ...
随机推荐
- spring框架之数组,集合(List,Set,Map),Properties等的注入
先编写User类: package com.huida.demo4; import java.util.Arrays; import java.util.List; import java.util. ...
- 使用jmeter工具测试上传接口
1.方法选择post:上传都是post上传. 2.路径输入正确的上传接口路径,并勾选Use multipart/form-data for POST 3.添加文件,文件路径尽量不要有中文,防止编码问题 ...
- LayDate 时间选择插件的使用介绍 (低版本1.0好像是)
<span style="font-size:18px;"><!doctype html> <html> <head> <me ...
- Jmeter中的XPath Assertion
XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历. XPath 是 W3C XSLT 标准的主要元素,并且 XQuery 和 XPointe ...
- 图片素材类Web原型制作分享-Pexels
Pexels是一个高清图片下载服务站点,为用户提供海量共享图片素材的网站,每周都会定量更新. 菜单栏和底部栏都是悬浮在固定位置,内容区域滚动.首页图片排列采用瀑布流的方式,多图片滚动.包含的页面有:浏 ...
- mybatis 和 mybatis-spring
一. 1. 实体bean package com.mybatisBean; public class User { private Integer id; private String name; ...
- 2018.07.08 hdu5316 Magician(线段树)
Magician Problem Description Fantasy magicians usually gain their ability through one of three usual ...
- Django入门与实践-第20章:QuerySets(查询结果集)(完结)
http://127.0.0.1:8000/boards/1/ #boards/models.py from django.utils.text import Truncator class Topi ...
- MySQL的NO_BACKSLASH_ESCAPES
官方说明: https://dev.mysql.com/doc/refman/5.7/en/mysql-real-escape-string.html 相关资料: https://dev.mysql. ...
- 反爬虫破解系列-汽车之家利用css样式替换文字破解方法
网站: 汽车之家:http://club.autohome.com.cn/ 以论坛为例 反爬虫措施: 在论坛发布的贴子正文中随机抽取某几个字使用span标签代替,标签内容位空,但css样式显示为所代替 ...