1 //十三周总结 2 //在看挑战程序设计的第二章和第三章的第一节 3 //二分 4 //1.从一个 有序的数组里面查找某一个值 5 int pos=lower_bound(a,a+n,key)-a;//返回的pos是大于等于键值的第一个位置 6 int pos=upper_bound(a,a+....
分类:
其他好文 时间:
2015-06-14 10:45:20
阅读次数:
168
ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, last)中的第一个大于等于值val的位置。ForwardIter upper_bound(ForwardIte...
分类:
其他好文 时间:
2015-06-11 14:35:01
阅读次数:
105
ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, last)中的第一个大于等于值val的位置。
ForwardIter upper_bound(ForwardIter first, ForwardIter last, const _Tp& val...
分类:
其他好文 时间:
2015-06-09 17:27:31
阅读次数:
98
题目链接 :超级赛亚ACMer看别人AC代码学会了一个C++STL lower_boundForwardIterlower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, last)中的第一个大于...
分类:
其他好文 时间:
2015-05-30 22:31:51
阅读次数:
162
4 Values whose Sum is 0
Time Limit: 15000MS
Memory Limit: 228000K
Total Submissions: 16970
Accepted: 4954
Case Time Limit: 5000MS
Description
The SUM problem can b...
分类:
其他好文 时间:
2015-05-29 13:59:50
阅读次数:
164
题目传送门 1 /* 2 题意:查询x的id,每次前排的树倒下 3 使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序) 4 */ 5 #include 6 #include 7 #include 8 using namespac...
分类:
其他好文 时间:
2015-05-27 22:43:25
阅读次数:
238
原题链接:http://ac.jobdu.com/problem.php?pid=1349二分。。 1 #include 2 #include 3 #include 4 #include 5 using std::lower_bound; 6 using std::upper_bound; 7 co...
分类:
编程语言 时间:
2015-05-27 13:44:30
阅读次数:
208
关于STL中的排序和检索,排序一般用sort函数即可,今天来整理一下检索中常用的函数——lower_bound , upper_bound 和 binary_search 。 STL中关于二分查找的函数有三个lower_bound 、upper_bound 、binary_search 。这三...
分类:
其他好文 时间:
2015-05-26 22:57:11
阅读次数:
209
分析:借助STL的multiset实现,很方便。
#include
#include
using namespace std;
class Node
{
public:
Node(int _h=0,int _pos=0):h(_h),pos(_pos) //注意_h一定要在_pos的前面,方便lower_bound的调用
{
}
int pos,h;
};
...
分类:
其他好文 时间:
2015-05-25 16:39:22
阅读次数:
105
题意:
给出一组数据n个数,m个询问q,问最近的q的输入下标是多少?分析:
首先数据量比较大100000,查询的话肯定要用些技巧,刚开始想的是二分查询,用set,可是不知道set里放数据结构struct如何按照关键字lower_bound()。后来看了官方题解,先把数据离散话,然后利用set[]来存储下标。那么输出的时候就直接输出begin,删除也可以erase().
这里有个trick,刚开...
分类:
其他好文 时间:
2015-05-24 08:52:50
阅读次数:
113