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 基准时间限 ...
随机推荐
- ASP.NET MVC 页面使用富文本控件的XSS漏洞问题
目前在做的项目存在XSS安全漏洞! 原因是有一些页面使用了富文本编辑框,为了使得其内容可以提交,为相关action设置了[ValidateInput(false)] 特性: [HttpPost] [V ...
- TCP/IP笔记之OSI和TCP/IP
- 升级python到最新2.7.13
python2.7是2.X的最后一个版本,同时也加入了一部分3.X的新特性.并且具有更好的性能,修改多个bug.所以决定升级到最新的2.7版,我的目前的版本是2.6.6 查看当前python版本 # ...
- 物体position:absolute后设置left:50%发生的有趣小事
今天在重构ui控件中3秒hint提示框样式,发现了一个有趣的小事,特发个文章记录一下,方便自己日后看一下 一 准备知识 ①一个已设置宽高的块状元素设置position:absolute后会保持他原来宽 ...
- HDU3183 A Magic Lamp —— 贪心(单调队列优化)/ RMQ / 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题解: 方法一:贪心. 在草稿纸上试多几次可以知道,删除数字中从左到右最后一位递增(可以等于)的 ...
- postNotificationName 消息传递详解
1.定义消息创建的关联值 也就是找到方法的标志 NSString *const GameToIPhoneNotification = @"GameToIPhoneNotification ...
- 客户端调用cxf发布的服务
import java.util.ArrayList; import java.util.List; import javax.xml.namespace.QName; import org.apac ...
- 将PHP数组输出为HTML表格
1. [代码][PHP]代码 <?phpclass xtable{ private $tit,$arr,$fons,$sextra; public function __con ...
- RTree算法Java实现 JSI RTree Library的调用实例 标签:jsi-rtree-library
1. [代码]jsi-rtree-library /** * */package com.mycompany.project; //package net.sourceforge.jsi.examp ...
- 手把手教你打造ImageView支持手势放大缩小
写在前面 最近有了新的任务,学习的时间比以前少了不少,Java回炉的文估计是得缓缓了,不过每周一篇尽量保质保量.最近感觉我文写的有点不好,因为我写东西除非必要,不然概念性的东西我基本上都是一笔带过…… ...