zoukankan      html  css  js  c++  java
  • 51Nod 1278 相离的圆

    平面上有N个圆,他们的圆心都在X轴上,给出所有圆的圆心和半径,求有多少对圆是相离的。
    例如:4个圆分别位于1, 2, 3, 4的位置,半径分别为1, 1, 2, 1,那么{1, 2}, {1, 3} {2, 3} {2, 4} {3, 4}这5对都有交点,只有{1, 4}是相离的。
    Input
    第1行:一个数N,表示圆的数量(1 <= N <= 50000)
    第2 - N + 1行:每行2个数P, R中间用空格分隔,P表示圆心的位置,R表示圆的半径(1 <= P, R <= 10^9)
    Output
    输出共有多少对相离的圆。
    Input示例
    4
    1 1
    2 1
    3 2
    4 1
    Output示例
    1
    保存一个圆的左右端点,二分搜索减去相切的就可以了。
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/stck:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF 0x3f3f3f3f
    #define mem(a) ((a,0,sizeof(a)))
    typedef long long ll;
    ll n,l[50006],r[500006],x,y;
    map<ll,int>m;
    int main()
    {
        scanf("%lld",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%lld%lld",&x,&y);
            l[i]=x-y;
            r[i]=x+y;
            m[l[i]]++;
        }
        sort(r,r+n);
        sort(l,l+n);
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            int k=lower_bound(l,l+n,r[i])-l;
            ans+=n-k-m[r[i]];
        }
        printf("%lld
    ",ans);
        return 0;
    }
  • 相关阅读:
    设计模式
    包装类
    php 闭包的理解
    is_null empty isset等的判定
    PHP基础一 $this ,static 和 self的区别
    lumen安装踩过得坑
    composer的使用和安装
    使用submine来写c++
    php 和 thinkphp中的常量一览
    路径问题 ./ / ../ 空 的区别
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/8973734.html
Copyright © 2011-2022 走看看