POJ2785(upper_bound)
#include"cstdio"
#include"algorithm"
using namespace std;
const int MAXN=;
int A[MAXN],B[MAXN],C[MAXN],D[MAXN];
int CD[MAXN*MAXN];
int n;
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d %d %d %d",&A[i],&B[i],&C[i],&D[i]); for(int i=;i<n;i++)
for(int j=;j<n;j++) CD[i*n+j]=C[i]+D[j];
sort(CD,CD+n*n); int res=;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
res+=upper_bound(CD,CD+n*n,-(A[i]+B[j]))-lower_bound(CD,CD+n*n,-(A[i]+B[j]));
printf("%d\n",res); }
return ;
}
POJ2785(upper_bound)的更多相关文章
- STL源码学习----lower_bound和upper_bound算法
转自:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html 先贴一下自己的二分代码: #include <cstdio&g ...
- 【刷题记录】 && 【算法杂谈】折半枚举与upper_bound 和 lower_bound
[什么是upper_bound 和 lower_bound] 简单来说lower_bound就是你给他一个非递减数列[first,last)和x,它给你返回非递减序列[first, last)中的第一 ...
- STL_lower_bound&upper_bound用法
ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, la ...
- STL之lower_bound和upper_bound
ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, la ...
- LeetCode:Search Insert Position,Search for a Range (二分查找,lower_bound,upper_bound)
Search Insert Position Given a sorted array and a target value, return the index if the target is fo ...
- [STL] lower_bound和upper_bound
STL中的每个算法都非常精妙, ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一 ...
- STL lower_bound upper_bound binary-search
STL中的二分查找——lower_bound .upper_bound .binary_search 二分查找很简单,原理就不说了.STL中关于二分查找的函数有三个lower_bound .upper ...
- vector的插入、lower_bound、upper_bound、equal_range实例
对于这几个函数的一些实例以便于理解: #include <cstdlib> #include <cstdio> #include <cstring> #includ ...
- STL中的lower_bound和upper_bound的理解
STL迭代器表述范围的时候,习惯用[a, b),所以lower_bound表示的是第一个不小于给定元素的位置 upper_bound表示的是第一个大于给定元素的位置. 譬如,值val在容器内的时候,从 ...
随机推荐
- iOS11 push控制器tabbar上移问题
解决方法 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { // 如果有大 ...
- SQL查询 [SCOPE_IDENTITY、IDENT_CURRENT 和 @@IDENTITY的区别(比较)] ---转载
@@IDENTITY (Transact-SQL) 返回最后插入的标识值的系统函数. 备注 在一条 INSERT.SELECT INTO 或大容量复制语句完成后,@@IDENTITY 中包含语句生成的 ...
- Android笔记之GridView
完整Demo链接:https://pan.baidu.com/s/1d_G9aCwBxpiYQcdQhwSDDw,提取码:5deh 效果图 activity_main.xml <?xml ver ...
- spring AOP操作
在spring进行AOP操作,使用aspectj实现 一.aspectj准备 aspectj不是spring的一部分,和spring一起使用进行AOP的操作 1.除了spring基本的jar包还需要导 ...
- 【足迹C++primer】32、定制操作_1
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/cutter_point/article/details/32066151 定制操作 向算法传递函数 ...
- ssh允许root用户登陆
新的系统无root用户密码,设置root用户密码,修改也是这么修改 sudo passwd root 连续输入两次新密码. 允许root用户登陆: /etc/ssh/sshd_config 找到 Pe ...
- P2455 [SDOI2006]线性方程组
P2455 [SDOI2006]线性方程组 真\(\cdot\)高斯消元模板题 由于各种hack数据被造出来~码量突增~,其实也就多了二三十行 将每行系数消到最多有一个非0数 特殊情况: 在过程同时 ...
- mini2440移植uboot 2011.03(上)
参考博文: <u-boot-2011.03在mini2440/micro2440上的移植> 本来我想移植最新版的uboot,但是移植却不太成功,所以先模仿他人的例子重新执行一遍,对uboo ...
- [转]Tomcat启动分析
[转]Tomcat启动分析 原帖 http://docs.huihoo.com/apache/tomcat/heavyz/01-startup.html 以下摘录了部分 --------------- ...
- 在cmd中将FAT32转换为NTFS分区的命令是什么?
将FAT32转换为NTFS分区的命令是什么? ========================================== 在cmd命令行模式下输入: convert x: /fs:ntfs ...