zoukankan      html  css  js  c++  java
  • poj-1328(贪心+思维)

    题目链接:传送门

    思路:找最少有几个点,先求出每个点的覆盖范围,就是一个点最大可以到达的地方是y相同的地方而且直线距离是d,

    所以x范围在[x-sqrt(d*d-y*y),x+sqrt(d*d-y*y)]内均符合条件;如果有相交的地方就是可以忽略这个点。

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    const int maxn = 1200;
    struct Node{
        double l,r;
        int x,y;
    };
    bool cmp(Node a,Node b)
    {
        return a.r<b.r;
    }
    Node vc[maxn];
    int main(void)
    {
        int i,j,cnt,n,d,fg,x,y,pt=1;
        while(scanf("%d%d",&n,&d)&&(n+d))
        {
            for(fg=0,i=0;i<n;i++)
            {
                scanf("%d%d",&vc[i].x,&vc[i].y);
                if(vc[i].y>d) fg=1;
            }
            if(fg==1)
            {
                printf("Case %d: -1
    ",pt++);
                continue;
            }
            for(i=0;i<n;i++)
            {
                vc[i].l=vc[i].x-sqrt(d*d*1.0-vc[i].y*vc[i].y*1.0);
                vc[i].r=vc[i].x+sqrt(d*d*1.0-vc[i].y*vc[i].y*1.0);
            }
            sort(vc,vc+n,cmp);
            for(i=0,cnt=0;i<n;)
            {
                double tp=vc[i].r;
                while(tp>=vc[i].l&&tp<=vc[i].r) i++;
                cnt++;
            }
            printf("Case %d: %d
    ",pt++,cnt);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Sunnypig闯三角关
    送给圣诞夜的贺卡
    uva 1592(NEERC 2009 STL)
    uva 297(传递闭包 WF 1996)
    hdu 4190(二分)
    uva 3592 (MST, kruskal)
    uva 11997 (基础数据结构)
    hdu 2680 (Dijkstra)
    hdu 4568(状态压缩dp)
    hdu 4582 (树上的贪心)
  • 原文地址:https://www.cnblogs.com/2018zxy/p/10301081.html
Copyright © 2011-2022 走看看