• 贪心- Radar Installation POJ


    贪心+预处理

    有个点 就是写错了,找了半天哇。 R是double类型不是int类型!

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <limits> 
    #include<cmath>
    #include <algorithm>
    #define endl '
    '
    #define _for(i,a,b) for(int i=a;i<b;i++)
    using namespace std;
    const int N = 1e4+5;
    typedef long long ll;
    int n,d; 
    struct Node{
        double l,r;
        bool operator < ( const Node &o )const{
            if( l!=o.l )
                return l<o.l;
            return r<o.r;
        }
    }a[N]; 
    int main(){
        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); 
        int Case = 1;
        while(cin>>n>>d){
            int flag = 0;
            if( n+d==0 ) break;
            _for(i,0,n){
                int x,y; cin>>x>>y;
                if( flag  ) continue;
                if( abs(y)>d ){
                    flag = 1; continue;
                }
                double py = sqrt( d*d - y*y );
                a[i].l = x-py,a[i].r = x+py;
            }
            if( flag ){
                cout<<"Case "<<Case++<<": "<<-1<<endl;
                continue; 
            }
            sort( a,a+n );
            double R = a[0].r; int cnt = 1;
            _for(i,1,n){
                if( a[i].r < R ) R = a[i].r;
                else if( a[i].l > R ){
                    cnt++;
                    R = a[i].r;
                }
            } 
            
            cout<<"Case "<<Case++<<": "<<cnt<<endl;
        }
        return 0;
    }
  • 相关阅读:
    conda环境配置以及pyinstaller报错配置
    软件测试的艺术--读书笔记
    flex布局相关
    移动端特殊样式
    css3中的2D转换
    logo seo优化
    html5 简单的新特性
    css中溢出文字省略号方式
    css用户界面样式
    精灵图与字体图标相关
  • 原文地址:https://www.cnblogs.com/SunChuangYu/p/12541805.html
Copyright © 2020-2023  润新知