http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278

因为圆心都在x轴上,把每个圆转化成线段后,按线段的起点排序,那么对于每个圆都要从后面找出起点大于当前圆转化成的线段终点的一个点,这个点之后的圆都会与当前圆相离.

因为按起点排序所以可以二分求解.

发现自己二分写的乱七八糟的.

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <vector>
  5. #include <cstring>
  6. #include <string>
  7. #include <algorithm>
  8. #include <string>
  9. #include <set>
  10. #include <functional>
  11. #include <numeric>
  12. #include <sstream>
  13. #include <stack>
  14. #include <map>
  15. #include <queue>
  16. #pragma comment(linker, "/STACK:102400000,102400000")
  17. #define CL(arr, val) memset(arr, val, sizeof(arr))
  18.  
  19. #define ll long long
  20. #define inf 0x7f7f7f7f
  21. #define lc l,m,rt<<1
  22. #define rc m + 1,r,rt<<1|1
  23. #define pi acos(-1.0)
  24.  
  25. #define L(x) (x) << 1
  26. #define R(x) (x) << 1 | 1
  27. #define MID(l, r) (l + r) >> 1
  28. #define Min(x, y) (x) < (y) ? (x) : (y)
  29. #define Max(x, y) (x) < (y) ? (y) : (x)
  30. #define E(x) (1 << (x))
  31. #define iabs(x) (x) < 0 ? -(x) : (x)
  32. #define OUT(x) printf("%I64d\n", x)
  33. #define lowbit(x) (x)&(-x)
  34. #define Read() freopen("a.txt", "r", stdin)
  35. #define Write() freopen("b.txt", "w", stdout);
  36. #define maxn 1000000000
  37. #define N 2510
  38. #define mod 1000000000
  39. using namespace std;
  40.  
  41. struct node
  42. {
  43. int x,y;
  44. bool operator < (const node a) const
  45. {
  46. if(x==a.x) return y<a.y;
  47. return x<a.x;
  48. }
  49. }p[];
  50. int n;
  51. int erfen(int a,int b)
  52. {
  53. int l=a,r=n-,mid=;
  54. while(l<=r)
  55. {
  56. mid=(l+r)/;
  57. if(p[mid].x>b) r=mid-;
  58. else l=mid+;
  59. }
  60. if(p[mid].x<=b) mid++;
  61. if(mid>=n) return n;
  62. else return mid;
  63. }
  64.  
  65. int main()
  66. {
  67. //freopen("a.txt","r",stdin);
  68. int a,b;
  69. scanf("%d",&n);
  70. for(int i=;i<n;i++)
  71. {
  72. scanf("%d%d",&a,&b);
  73. p[i].x=a-b;
  74. p[i].y=a+b;
  75. }
  76. sort(p,p+n);
  77. //for(int i=0;i<n;i++)
  78. //{
  79. // printf("%d %d\n",p[i].x,p[i].y);
  80. //}
  81. int num=;
  82. for(int i=;i<n-;i++)
  83. {
  84. int x=erfen(i+,p[i].y);
  85. num+=n-x;
  86. // printf("%d %d\n",num,x);
  87.  
  88. }
  89. printf("%d\n",num);
  90. return ;
  91. }

当然也可以直接把p[i].x赋值给另外一个一维数组,然后就可以用upper_bound实现二分查找了.

51nod - 1278 相离的圆 (二分)的更多相关文章

  1. 51Nod 1278 相离的圆

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

  2. 【51nod-1278】相离的圆(二分)

    思路 做法就是先把圆的直径化成线段,然后将线段的起点从小到大排序,以第i条线段为例,找i+1~n条中这样一条线段,满足是第一条且起点比第i条的终点要大(即满足相离),那么包括这条线段之后的线段也满足和 ...

  3. 51nod 1105(第K大数 二分套二分)

    题目链接:http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=620811 参考自:https://blog.csdn.net/f_ ...

  4. 51nod 1640 天气晴朗的魔法 二分 + 克鲁斯卡算法(kruskal算法) 做复杂了

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1640 一开始想的时候,看到要使得最大值最小,那这样肯定是二分这个最大值了 ...

  5. 51nod 第K大区间2(二分+树状数组)

    题目链接: 第K大区间2 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 160 定义一个长度为奇数的区间的值为其所包含的的元素的中位数.中位数_百度百科 现给出n个数,求将所有长度为 ...

  6. 51Nod 1557 两个集合(二分)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1557 题意: 小X有n个互不相同的整数: p1,p2,...,pn .他 ...

  7. 51nod 1686 第K大区间 二分瞎搞

    题目: 定义一个区间的值为其众数出现的次数. 现给出n个数,求将所有区间的值排序后,第K大的值为多少. 题解: 答案明显单调,我们考虑二分答案. 转化为判定问题后我们需要观察到一个性质: 如果一个区间 ...

  8. 51NOD 1962 区间计数 单调栈+二分 / 线段树+扫描线

     区间计数   基准时间限制:1.5 秒 空间限制:262144 KB 分值: 80   两个数列 {An} , {Bn} ,请求出Ans, Ans定义如下: Ans:=Σni=1Σnj=i[max{ ...

  9. 51nod 1278【贪心】

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

随机推荐

  1. 阿里maven仓库地址

    在国内访问Maven仓库,连接速度太慢.下面是将中央仓库替换成阿里云的中央仓库的方法. 第一种,统一修改仓库地址 可以直接修改Mavenconf文件夹中的setting.xml文件,或者在.m2文件夹 ...

  2. IIS 的最大并发数

    为了探寻IIS的最大并发数,先要做几个假设. 1.假设最大并发数就是当前的连接数.意思是当前能承受最大的连接,那么就表明最大的并发.2.假设IIS应用程序池处于默认状态,更改设置将会对最大连接数产生影 ...

  3. 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 ...

  4. input 全选 jquery封装方法

    HTML代码 <table class="table table-striped"> <thead> <tr> <th><in ...

  5. Scala基础篇-函数式编程的重要特性

    1.纯函数 表示函数无副作用(状态变化). 2.引用透明性 表示对相同输入,总是得到相同输出. 3.函数是一等公民 函数与变量.对象.类是同一等级.表示可以把函数当做参数传入另一个函数,或者作为函数的 ...

  6. iOS:swift :可选类型

    import UIKit /*: 可选类型 * 可选类型表示变量可以有值, 也可以没有值 * C 和 Objective-C 中并没有可选类型这个概念 * Swift中只有可选类型才可以赋值为nil ...

  7. Node.js——基本服务开启

    标注模式 var http = require('http'); var server = http.createServer(); server.on('request', function (re ...

  8. 初学者SQL shell(psql)无法登陆问题

    因为项目第一次接触postgresql,有个问题搞死我了,如果初学,估计大家也会遇见这样的问题,希望可以节约时间. 用户postgres的口令不显示啊!服!

  9. Farseer.net轻量级开源框架 中级篇:BasePage、BaseController、BaseHandler、BaseMasterPage、BaseControls基类使用

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: UrlRewriter 地址重写 下一篇:Farseer.net轻量级开源框架 中 ...

  10. jQuery 返回顶部效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...