主要这道题没有包含的情况,所以直接搞个左端,然后对于每个二分求一下>right的最近的位置j,那么ans就会增加 j 以后的;

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
using namespace std; const int N=5e4+10;
struct asd{
int x,y;
};
asd q[N];
int n; bool cmp(asd a,asd b)
{
return a.x<b.x;
} int Find(int s,int e,int tmp)
{
int left=s;
int right=e;
while(left <= right)
{
int mid = (left+right) >> 1;
if(q[mid].x > tmp)
right = mid-1;
else
left = mid+1;
}
return left;
} int main()
{
int d,r;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&d,&r);
q[i].x=d-r;
q[i].y=d+r;
}
sort(q,q+n,cmp);
int j;
int ans=0;
for(int i=0;i<n-1;i++)
{
j=Find(i+1,n-1,q[i].y);
ans+=n-j;
}
printf("%d\n",ans);
return 0;
}

51nod 1278【贪心】的更多相关文章

  1. 51Nod 1278 相离的圆

    51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...

  2. 51nod 1163贪心

    用优先队列来贪心,是一个很好地想法.优先队列在很多时候可以维护最值,同时可以考虑到一些其他情况. http://www.51nod.com/onlineJudge/questionCode.html# ...

  3. 51nod 1625 贪心/思维

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 1625 夹克爷发红包 基准时间限制:1 秒 空间限制:13107 ...

  4. 51nod 1099 贪心/思维

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 1099 任务执行顺序 基准时间限制:1 秒 空间限制:13107 ...

  5. 51nod 1428 贪心

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...

  6. 51nod - 1278 相离的圆 (二分)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 因为圆心都在x轴上,把每个圆转化成线段后,按线段的起点排序,那么对 ...

  7. 51nod 1672 贪心/队列

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...

  8. 51nod 1449 贪心

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1449 1449 砝码称重 题目来源: CodeForces 基准时间限制 ...

  9. 51nod 1255 贪心/构造

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1255 1255 字典序最小的子序列 题目来源: 天津大学OJ 基准时间限 ...

随机推荐

  1. xpath 轴,节点之间的关系

    http://www.w3school.com.cn/xpath/xpath_axes.asp http://www.freeformatter.com/xpath-tester.html 测试 轴可 ...

  2. linux安装ssh(转载)

    CentOS安装ssh最笨的方法:yum install ssh yum install openssh-server/etc/init.d/sshd status看sshd服务的状态/etc/ini ...

  3. MSQL Webpage

    Mars Nov 19, 2014

  4. 搭建React Native开发环境

    搭建React Native开发环境 本文档是Mac下搭建的环境,针对的目标平台不同,以及开发 iOS 和 Android 的不同,环境搭建也有差异. Github地址:https://github. ...

  5. 多线程(C++)临界区Critical Sections

    一 .Critical Sections(功能与Mutex相同,保证某一时刻只有一个线程能够访问共享资源,但是不是内核对象,所以访问速度比Mutex快,但是没有等待超时的功能,所以有可能导致死锁,使用 ...

  6. Hybrid--WebView中使用Ajax

    Hybrid框架下的app,使用的Ajax.须要注意的是UIWebViewDelegate不会监測到Ajax的request.也就是再运行Ajax代码时.shouldStartLoadWithReuq ...

  7. windows 复制 文本文件内容 到剪切板

    shell  打开 type filename | clip

  8. curl is a tool to transfer data from or to a server curl POST

    https://curl.haxx.se/docs/manpage.html curl is a tool to transfer data from or to a server, using on ...

  9. linux环境下远程访问ftp

    sftp ftpuser@127.0.0.1 使用sftp命令 ftpuser是用户名 127.0.0.1是目标ip 亲测好使.

  10. Eclipse快捷键【转载】

    分享一前辈的博客-Eclipse快捷键