UVA - 10382 (区间贪心)

注意每个圆管辖的区间不是最左或最右的端点而是和被覆盖图形的交点。

直接按照每个圆的left排序

每次尽量寻找靠右的就可以了。

#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#define INF  0x3f3f3f3f
using namespace std;
//int n, m,q ;
typedef long long LL;
const double PI = 3.141592653589793;
const double r = 6378 ;
const int maxn = 10000+10;

int n,l,w;
struct Point
{
    double pos,r,st,ed;
} s[maxn];
bool cmp(const Point &t1, const Point & t2)
{

    return t1.st < t2.st;
}
int main()
{
    while(cin >> n >> l >> w)
    {
        int E = 0;
        double a,b;
        for(int i = 0 ; i < n ; i++)
        {
            cin >> a >> b;
            if(b*2 > w)
            {
                s[E].pos = a ;
                s[E].r = b;
                s[E].st=s[E].pos - sqrt(1.0*b*b-1.0*w*w/4);
                s[E].ed = s[E].pos + sqrt(1.0*b*b-1.0*w*w/4);
                E++;
            }
        }
        sort(s,s+E,cmp);

        if(s[0].st > 0)
        {
            cout << "-1" << endl;
            continue;
        }
        double up = 0;
        double low = 0;
        int sum = 0;
        while(up < l)
        {
            double low1;
            bool flag = false;
            for(int j = 0; j < E ; j++)
            {
                if(s[j].st <= low && s[j].ed > up)
                {
                    up = s[j].ed;
                    flag = true;
                }
            }
            if(!flag)
            {
                sum=-1;
                break;
            }
            low = up;
            sum++;
        }
        cout << sum << endl;
    }
    return 0;
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值