51nod 1278【贪心】
主要这道题没有包含的情况,所以直接搞个左端,然后对于每个二分求一下>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【贪心】的更多相关文章
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
- 51nod 1163贪心
用优先队列来贪心,是一个很好地想法.优先队列在很多时候可以维护最值,同时可以考虑到一些其他情况. http://www.51nod.com/onlineJudge/questionCode.html# ...
- 51nod 1625 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 1625 夹克爷发红包 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1099 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 1099 任务执行顺序 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1428 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...
- 51nod - 1278 相离的圆 (二分)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 因为圆心都在x轴上,把每个圆转化成线段后,按线段的起点排序,那么对 ...
- 51nod 1672 贪心/队列
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...
- 51nod 1449 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1449 1449 砝码称重 题目来源: CodeForces 基准时间限制 ...
- 51nod 1255 贪心/构造
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1255 1255 字典序最小的子序列 题目来源: 天津大学OJ 基准时间限 ...
随机推荐
- TCP协议和socket API 学习笔记
本文转载至 http://blog.chinaunix.net/uid-16979052-id-3350958.html 分类: 原文地址:TCP协议和socket API 学习笔记 作者:gilb ...
- windows 打开文件夹
@echo off rem 建立链接 net use \\192.168.2.3\share /user:username password rem 打开共享文件夹 explorer \\192.16 ...
- 【计蒜客2017NOIP模拟赛1】
D1T1 题面 题解:一开始以为傻题,旋转个坐标系就行了,结果光荣爆零~ 结果发现旋转坐标系后,由于多了一些虚点,锤子砸到虚点上了~gg [没有代码] D1T2 题面 题解:计算出每个边对答案的贡献即 ...
- c++的运算符的重载
1 什么是c++运算符的重载 c++运算符的重载就是说对+.-.>.<等运算符进行重新定义,这样的话,除了基本的类型,所有的类都可以进行基本的运算了,用起来非常方便.特别是用在各种算法中. ...
- office web apps的搭建部署(1)(写于2017.12.27)
因为业务方面的需求,项目要求搭建office-web-apps这个玩意儿,做一个在线预览编辑的功能,为了方便,我下面都用OWA代替这个服务. 首先说一下什么是office-web-apps-serve ...
- RobotFramework教程使用笔记——requests和requestslibrary库
Robotframework也可以进行接口测试,只要导入相应的库就可以做到. 一.准备工作 1.导入requests,使用pip,或者手动下载 pip install requests 2.导入req ...
- RobotFramework教程使用笔记——Selenium2Library库
selenium之前已经学习介绍过了,它是一个支持多语言.多平台.多浏览器的web自动化测试框架,在robotframework中也可以导入selenium库来进行web自动化测试.它使用seleni ...
- 关于git上传文件的一个小问题
*** Please tell me who you are. Run git config --global user.email "you@example.com" git c ...
- hadoop集群部署后,遇到的问题记录
1. 部署完,启动集群后,mapred-site.xml文件中配置没有生效 <property> <name>mapred.job.tracker</name> ...
- static静态数据的初始化
package com.demo.book; public class StaticInitialization { static Table table = new Table(); static ...