uva1615 Highway

Posted lqerio

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva1615 Highway相关的知识,希望对你有一定的参考价值。

画图,每个给出点都有对应区间;先sort,再尽量靠右选;很常见的套路了..//注意不要越界(0,L)

struct Q //复习结构
{
double l,r;
Q(double _l,double _r):l(_l),r(_r){}
bool operator < (const Q &a) const {
return r<a.r;
}
};

 

#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
struct village
{
    double l,r;
    village(double _l,double _r):l(_l),r(_r){}
    bool operator < (const village &a) const {
        return r<a.r;
    }
};
vector<village>vec;
int length,D,n;


void dist(int x,int y,double &l,double &r)
{
    l=(double)x-sqrt((double)D*(double)D-(double)y*(double)y);
    r=(double)x+sqrt((double)D*(double)D-(double)y*(double)y);
}

int main()
{
    int x,y;
    double l,r;
    while(scanf("%d",&length)!=EOF)
    {
        scanf("%d%d",&D,&n);
        vec.clear();
        for(int i=0;i<n;++i){
            scanf("%d%d",&x,&y);
            dist(x,y,l,r);
            vec.push_back(village(max(0.0,l),min((double)length,r)));
        }
        sort(vec.begin(),vec.end());
         int ans=0;
         double temp=-1.0;
         for(int i=0;i<n;++i){
        if(temp<vec[i].l||temp>vec[i].r){
            ++ans;
            temp=vec[i].r;
            }
        }
        printf("%d
",ans);
    }
    return 0;
}

 








以上是关于uva1615 Highway的主要内容,如果未能解决你的问题,请参考以下文章

uva1615 Highway

UVa1615 Highway (贪心,区间选点)

luogu题解 UVA1615 Highway

习题 8-11 UVA - 1615Highway

UVA - 1615 Highway(高速公路)(贪心+区间选点)

UVa 1615 Highway (贪心,区间选点问题)