51nod - 1278 相离的圆 (二分)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278
因为圆心都在x轴上,把每个圆转化成线段后,按线段的起点排序,那么对于每个圆都要从后面找出起点大于当前圆转化成的线段终点的一个点,这个点之后的圆都会与当前圆相离.
因为按起点排序所以可以二分求解.
发现自己二分写的乱七八糟的.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 2510
#define mod 1000000000
using namespace std; struct node
{
int x,y;
bool operator < (const node a) const
{
if(x==a.x) return y<a.y;
return x<a.x;
}
}p[];
int n;
int erfen(int a,int b)
{
int l=a,r=n-,mid=;
while(l<=r)
{
mid=(l+r)/;
if(p[mid].x>b) r=mid-;
else l=mid+;
}
if(p[mid].x<=b) mid++;
if(mid>=n) return n;
else return mid;
} int main()
{
//freopen("a.txt","r",stdin);
int a,b;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&a,&b);
p[i].x=a-b;
p[i].y=a+b;
}
sort(p,p+n);
//for(int i=0;i<n;i++)
//{
// printf("%d %d\n",p[i].x,p[i].y);
//}
int num=;
for(int i=;i<n-;i++)
{
int x=erfen(i+,p[i].y);
num+=n-x;
// printf("%d %d\n",num,x); }
printf("%d\n",num);
return ;
}
当然也可以直接把p[i].x赋值给另外一个一维数组,然后就可以用upper_bound实现二分查找了.
51nod - 1278 相离的圆 (二分)的更多相关文章
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
- 【51nod-1278】相离的圆(二分)
思路 做法就是先把圆的直径化成线段,然后将线段的起点从小到大排序,以第i条线段为例,找i+1~n条中这样一条线段,满足是第一条且起点比第i条的终点要大(即满足相离),那么包括这条线段之后的线段也满足和 ...
- 51nod 1105(第K大数 二分套二分)
题目链接:http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=620811 参考自:https://blog.csdn.net/f_ ...
- 51nod 1640 天气晴朗的魔法 二分 + 克鲁斯卡算法(kruskal算法) 做复杂了
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1640 一开始想的时候,看到要使得最大值最小,那这样肯定是二分这个最大值了 ...
- 51nod 第K大区间2(二分+树状数组)
题目链接: 第K大区间2 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 160 定义一个长度为奇数的区间的值为其所包含的的元素的中位数.中位数_百度百科 现给出n个数,求将所有长度为 ...
- 51Nod 1557 两个集合(二分)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1557 题意: 小X有n个互不相同的整数: p1,p2,...,pn .他 ...
- 51nod 1686 第K大区间 二分瞎搞
题目: 定义一个区间的值为其众数出现的次数. 现给出n个数,求将所有区间的值排序后,第K大的值为多少. 题解: 答案明显单调,我们考虑二分答案. 转化为判定问题后我们需要观察到一个性质: 如果一个区间 ...
- 51NOD 1962 区间计数 单调栈+二分 / 线段树+扫描线
区间计数 基准时间限制:1.5 秒 空间限制:262144 KB 分值: 80 两个数列 {An} , {Bn} ,请求出Ans, Ans定义如下: Ans:=Σni=1Σnj=i[max{ ...
- 51nod 1278【贪心】
主要这道题没有包含的情况,所以直接搞个左端,然后对于每个二分求一下>right的最近的位置j,那么ans就会增加 j 以后的: #include <cstdio> #include ...
随机推荐
- vue.js学习参考手册
参考手册 示例:www.51siyuan.cn/161.html
- Spring注解驱动开发之扩展原理
前言:现今SpringBoot.SpringCloud技术非常火热,作为Spring之上的框架,他们大量使用到了Spring的一些底层注解.原理,比如@Conditional.@Import.@Ena ...
- Toolbar自定义布局
Toolbar如何使用想必大家清楚地很,实际开发中标题栏的样式各色各样,因此其基本样式便不能满足我们的需求,这就需要我们自定义布局.打开ToolBar源码我们发现它继承ViewGroup,这就表示我们 ...
- RFTWEB测试对象抓取的方法
本文转自:http://feiyeguohai.iteye.com/blog/1468576 Rational Functional Tester (RFT) 作为 IBM 自己设计研发的自动化测试工 ...
- SDK manager.exe 运行时报错:系统找不到指定的文件 android.bat
android studio 2.3.1的 SDK Manager工具 突然没有 Launcher XXX 那个按钮,只好到SDK目录中去启动,无奈发生以下错误. 解决办法:运行android.bat ...
- iOS-UI控件之UIImageView
contentMode属性 带有scale单词的:图片有可能会拉伸 UIViewContentModeScaleToFill 将图片拉伸至填充整个imageView 图片显示的尺寸跟imageView ...
- 关于AMAZON SES设置的一些要点
1.首先要有一个企业邮箱,如果没有可以去腾讯(http://exmail.qq.com/onlinesell/intro)申请一个,网易也有,不过解析几次搞了两天都是未通过,腾讯几分钟就好了 企业邮箱 ...
- 谈谈如何来查看GC日志
一.首先来看一下JVM中的GC有哪几种类型? 1.-XX:UseSerialGC 虚拟机运行在Client模式的默认值,打开此开关参数后,使用Serial+Serial Old收集器组合进行垃圾收集. ...
- java图片放大或缩小
package org.jimmy.autotranslate20181022.utils; import java.awt.Graphics; import java.awt.image.Buffe ...
- 数据结构之线性顺序表ArrayList(Java实现)
一.ListMe接口: import java.util.ArrayList; //实现线性表(顺序表和链表)的接口://提供add get isEmpty size 功能public interfa ...