#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)的更多相关文章

  1. STL源码学习----lower_bound和upper_bound算法

    转自:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html 先贴一下自己的二分代码: #include <cstdio&g ...

  2. 【刷题记录】 && 【算法杂谈】折半枚举与upper_bound 和 lower_bound

    [什么是upper_bound 和 lower_bound] 简单来说lower_bound就是你给他一个非递减数列[first,last)和x,它给你返回非递减序列[first, last)中的第一 ...

  3. STL_lower_bound&upper_bound用法

    ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, la ...

  4. STL之lower_bound和upper_bound

    ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, la ...

  5. 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 ...

  6. [STL] lower_bound和upper_bound

    STL中的每个算法都非常精妙, ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一 ...

  7. STL lower_bound upper_bound binary-search

    STL中的二分查找——lower_bound .upper_bound .binary_search 二分查找很简单,原理就不说了.STL中关于二分查找的函数有三个lower_bound .upper ...

  8. vector的插入、lower_bound、upper_bound、equal_range实例

    对于这几个函数的一些实例以便于理解: #include <cstdlib> #include <cstdio> #include <cstring> #includ ...

  9. STL中的lower_bound和upper_bound的理解

    STL迭代器表述范围的时候,习惯用[a, b),所以lower_bound表示的是第一个不小于给定元素的位置 upper_bound表示的是第一个大于给定元素的位置. 譬如,值val在容器内的时候,从 ...

随机推荐

  1. 【python】-- 装饰器、迭代器、生成器

    装饰器 装饰器本质是函数,是用来装饰其他函数,顾名思义就是,为其他的函数添加附件功能的. 一.装饰器原则: 不能修改被装饰函数的源代码 不能修改被装饰函数的调用方式 def logging(): pr ...

  2. IO多路复用的作用?并列举实现机制以及区别?

    I/O多路复用是用于提升效率,单个进程可以同时监听多个网络连接IO. 举例:通过一种机制,可以监视多个文件描述符,一旦描述符就绪(读就绪和写就绪),能通知程序进行相应的读写操作,I/O多路复用避免阻塞 ...

  3. python -virtualenvwrapper 切换不同的python版本

    环境: 安装了python2.7和python3.4, 两个版本都安装了virtualenv和virtualenvwrapper 在windows cmd中键入mkvirtualenv -p C:\P ...

  4. eclipse svn 分支合并到主干

    最近公司产品上线,整个系统架构包含有七八个子系统,并且子系统都是集群部署.所以每次升级维护都要确保尽可能不出问题.因为整个系统刚上线不久,意味着新系统不定期有BUG需修复,但新功能模块也在持续的开发中 ...

  5. 通过GPRS将GPS数据上传到OneNet流程

    AT OK AT+CGCLASS="B" OK AT+CGDCONT=1,"IP","CMNET" OK AT+CGATT=1 OK AT+ ...

  6. EntityFramework 学习 一 Delete Entity using DBContext in Disconnected Scenario

    Student studentToDelete; . Get student from DB using (var ctx = new SchoolDBEntities()) { studentToD ...

  7. 算法(Algorithms)第4版 练习 1.5.4

    代码实现: package com.qiusongde; import edu.princeton.cs.algs4.StdIn; import edu.princeton.cs.algs4.StdO ...

  8. hdoj1001--Sum Problem

    Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, y ...

  9. iOS App被拒原因以及解决方案总结。

    Guideline 1.2 - Safety - User Generated Content Your app enables the display of user-generated conte ...

  10. delphi完美经典-第16章 Delphi数据库程序设计----使用BDE组件

    第16章 Delphi数据库程序设计----使用BDE组件 Delphi访问数据库的方式有:ADO.BDE.dbExpress.InterBase Express. 一.TDataSet组件 虽然De ...