• 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
  • 相关阅读:
    日报10.29
    日报10.28
    日报10.27
    周进度总结-6
    日报10.25
    日报10.23
    日报10.22
    日报10.21
    日报10.18
    STL bitset
  • 原文地址:https://www.cnblogs.com/2018zxy/p/10301081.html
Copyright © 2020-2023  润新知