zoukankan      html  css  js  c++  java
  • poj 1328 贪心

    贪心。以每个岛屿为圆心,在x轴上求出雷达可能出现的区间,重叠的区间只用一个雷达

     1 #include <iostream>
    2 #include <algorithm>
    3 #include <cmath>
    4 #include <stdio.h>
    5 using namespace std;
    6 typedef double ll;
    7 const int maxx=1000;
    8 struct PO
    9 {
    10 ll l,r;
    11 };
    12 PO point[maxx+5];
    13
    14 bool cmp(PO a,PO b)
    15 {
    16 if(a.l==b.l) return a.r<b.r;
    17 return a.l<b.l;
    18 }
    19
    20 int main()
    21 {
    22 int n,i,d,cnt,tt=0,flag;
    23 ll a,b,ll,rr,temp1,temp2;
    24 //freopen("in.txt","r",stdin);
    25 while(scanf("%d%d",&n,&d)!=EOF)
    26 {
    27 if(n==0 && d==0) break;
    28 temp1=(d*1.0)*(d*1.0);
    29 flag=0;
    30 for(i=0;i<n;i++)
    31 {
    32 scanf("%lf%lf",&a,&b);
    33 temp2=b*b;
    34 if(d-b<0)
    35 flag=1;
    36 if(flag) continue;
    37 point[i].l=a-sqrt((temp1-temp2)*1.0);
    38 point[i].r=a+sqrt((temp1-temp2)*1.0);
    39 }
    40 if(flag){printf("Case %d: -1\n",++tt);continue;}
    41 sort(point,point+n,cmp);
    42 ll=point[0].l;
    43 rr=point[0].r;
    44 cnt=1;
    45 for(i=1;i<n;i++)
    46 {
    47 if(rr<point[i].l)
    48 {
    49 cnt++;
    50 rr=point[i].r;
    51 ll=point[i].l;
    52 }
    53 else if(rr>=point[i].l && rr<=point[i].r) ll=point[i].l;
    54 else{ll=point[i].l;rr=point[i].r;}
    55 }
    56 printf("Case %d: %d\n",++tt,cnt);
    57
    58 }
    59 return 0;
    60 }




  • 相关阅读:
    webpack入门
    vue 知识记录
    vue 服务端渲染案例
    nodemon的简单配置和使用
    vue 非父子组件通信-中转站
    position笔记
    koa 练习
    笔记
    git push代码时的'git did not exit cleanly (exit code 1)'问题解决
    块级元素的text-align对行内元素和果冻元素(inline-block)的作用
  • 原文地址:https://www.cnblogs.com/inpeace7/p/2428055.html
Copyright © 2011-2022 走看看