zoukankan      html  css  js  c++  java
  • 1278 相离的圆(51nod)

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

    这道题需要用到两个姿势第一将圆相离的模型转换成线段和线段之间不想交,然后还有一个就是修改循环变量的步长。达到降低时间复杂度的效果,不过只能降低系数,并不能降低次数= =

    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    #define inf 10000000
    using namespace std;
    struct node
    {
        int l,r;
    };
    bool cmp(node a,node b)
    {
        if(a.l==b.l)
            return a.r<b.r;
        return a.l<b.l;
    }
    node a[50000];
    int main()
    {
        int n,c,R;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
           scanf("%d %d",&c,&R);
           a[i].l=c-R;
           a[i].r=c+R;
        }
        sort(a,a+n,cmp);
       /* for(int i=0;i<n;i++)
        {
            printf("%d %d
    ",a[i].l,a[i].r);
        }*/
        int ans=0;
        int min;
        int i,j;
        for(i=0;i<n;i++)
        {
           for(j=i+100;j<n;j+=100)//在100的步长内进行寻找不相交的线段
           {
               if(a[j].l>a[i].r)
                break;
           }
           if(j>n) j=n;//大于n的时候要进行这步
           for(int k=j-1;k>=0&&k>j-101;k--)//然后在100内进行扫描
           {
               if(a[k].l<=a[i].r)
               {
                    ans+=n-(k+1);
                    break;
               }
           }
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    兼容性处理
    H5 IOS 虚拟键盘不回落的问题
    git 的版本控制
    vue-devtools工具的安装
    linux下安装mysql
    Python安装pip3常见问题
    linux下安装python3
    接口_注册接口
    接口_简单get接口_第一个接口
    Python学习笔记_Redis
  • 原文地址:https://www.cnblogs.com/NaCl/p/4725725.html
Copyright © 2011-2022 走看看