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 ...
随机推荐
- 阿里maven仓库地址
在国内访问Maven仓库,连接速度太慢.下面是将中央仓库替换成阿里云的中央仓库的方法. 第一种,统一修改仓库地址 可以直接修改Mavenconf文件夹中的setting.xml文件,或者在.m2文件夹 ...
- IIS 的最大并发数
为了探寻IIS的最大并发数,先要做几个假设. 1.假设最大并发数就是当前的连接数.意思是当前能承受最大的连接,那么就表明最大的并发.2.假设IIS应用程序池处于默认状态,更改设置将会对最大连接数产生影 ...
- LN : leetcode 312 Burst Balloons
lc 312 Burst Balloons 312 Burst Balloons Given n balloons, indexed from 0 to n-1. Each balloon is pa ...
- input 全选 jquery封装方法
HTML代码 <table class="table table-striped"> <thead> <tr> <th><in ...
- Scala基础篇-函数式编程的重要特性
1.纯函数 表示函数无副作用(状态变化). 2.引用透明性 表示对相同输入,总是得到相同输出. 3.函数是一等公民 函数与变量.对象.类是同一等级.表示可以把函数当做参数传入另一个函数,或者作为函数的 ...
- iOS:swift :可选类型
import UIKit /*: 可选类型 * 可选类型表示变量可以有值, 也可以没有值 * C 和 Objective-C 中并没有可选类型这个概念 * Swift中只有可选类型才可以赋值为nil ...
- Node.js——基本服务开启
标注模式 var http = require('http'); var server = http.createServer(); server.on('request', function (re ...
- 初学者SQL shell(psql)无法登陆问题
因为项目第一次接触postgresql,有个问题搞死我了,如果初学,估计大家也会遇见这样的问题,希望可以节约时间. 用户postgres的口令不显示啊!服!
- Farseer.net轻量级开源框架 中级篇:BasePage、BaseController、BaseHandler、BaseMasterPage、BaseControls基类使用
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: UrlRewriter 地址重写 下一篇:Farseer.net轻量级开源框架 中 ...
- jQuery 返回顶部效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...