• POJ--1328 Radar Installation(贪心 排序)


    题目:Radar Installation

    对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点

    排序之后贪心一下就ok

    用cin 好像一直t看了好多blog 改了scanf 过了

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<cmath>
    using namespace std;
    const int maxn=10001;
    int n,c[maxn];
    struct ac{
        double x,y;
    }a[maxn];
    bool cmp(ac q,ac w){
      return q.x<w.x;
    }
    int main(){
        int n,tot=1;
        double d;
        bool fa;
        cin>>n>>d;
        while(n!=0||d!=0){
           fa=0;
           for(int j=1;j<=n;j++){
             double x,y;
             scanf("%lf%lf",&x,&y);
             if(abs(y)>d) fa=1;
             else{
               a[j].x=x*1.0-sqrt(d * d - y * y);
               a[j].y=x*1.0+sqrt(d * d - y * y);
             }
           }
           int ans=1;
           if(fa||d<=0) printf("Case %d: -1
    ",tot++);
           else{
              sort(a+1,a+1+n,cmp);
              ac aa=a[1];
              for(int j=2;j<=n;j++){
                 if(a[j].x>aa.y){
                    ans++;
                    aa=a[j];
                 }else if(a[j].y<aa.y){
                    aa=a[j];
                 }
              }
              printf("Case %d: %d
    ",tot++,ans);
           }
           cin>>n>>d;
        }
        return 0;
    }
  • 相关阅读:
    1351. 统计有序矩阵中的负数
    剑指 Offer 56
    39. 组合总和
    1619. 删除某些元素后的数组均值
    1380. 矩阵中的幸运数
    216. 组合总和 III
    面试题 08.03. 魔术索引
    1518. 换酒问题
    Xcode多进程调试:WKWebView
    Xcode编译WebKit
  • 原文地址:https://www.cnblogs.com/Dvelpro/p/10029741.html
Copyright © 2020-2023  润新知