题目描述有些坑。。

题意:

  有一条高速公路在x轴上,从(0,0)到(L,0)。周围有一些村庄,希望能够在高速公路上开通几个出口,使得每个村庄到最近的出口距离小于D,求出最少需要开通多少个出口。

解题思路:

  典型的区间问题,将每个点化为区间(x-sqrt(D^2-y^2),x+sqrt(D^2+y^2)),然后按区间右端点排序,依次对每个区间进行操作,如果该区间中已有出口则无需增加,若该区间没有出口则取右端点为出口。

  可以证明,这是最优方案,得到最少出口数。

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#define eps 1e-6
using namespace std;
int n,ans;
double p,q,h,L,D;
struct point{
double x,y;
}a[];
bool cmp(point a,point b){
if(a.y<b.y) return ;
return ;
}
int main()
{
while(scanf("%lf%lf%d",&L,&D,&n)==){
for(int i=;i<n;i++){
scanf("%lf%lf",&p,&q);
a[i].x=p-sqrt(fabs(D*D-q*q));
a[i].y=p+sqrt(fabs(D*D-q*q));
}
sort(a,a+n,cmp);
h=-;
ans=;
for(int i=;i<n;i++)
if(!((h>a[i].x||fabs(h-a[i].x)<eps)&&(h<a[i].y||fabs(h-a[i].y<eps)))){
h=a[i].y;
if(h>L&&fabs(h-L)>eps) h=L;
ans++;
}
printf("%d",ans);
}
return ;
}

POJ3485 区间问题的更多相关文章

  1. ASP.NET Core应用针对静态文件请求的处理[2]: 条件请求与区间请求

    通过调用ApplicationBuilder的扩展方法UseStaticFiles注册的StaticFileMiddleware中间件帮助我们处理针对文件的请求.对于StaticFileMiddlew ...

  2. SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等

    在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...

  3. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  4. codevs 1082 线段树区间求和

    codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运 ...

  5. [LeetCode] Find Right Interval 找右区间

    Given a set of intervals, for each of the interval i, check if there exists an interval j whose star ...

  6. [LeetCode] Non-overlapping Intervals 非重叠区间

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  7. [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  8. [LeetCode] Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

  9. [LeetCode] Summary Ranges 总结区间

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

随机推荐

  1. 团队作业week2-软件分析和用户需求调查

    我们的团队选择评定的软件是必应词典(iphone版)和使用较多的有道词典(iphone版)   类别 描述 评分(Bing) 评分(有道)  功能      核心功能1:词典 顾名思义,作为一款词典类 ...

  2. java 把URL中的中文转换成utf-8编码

    private static final String QUERY = "餐饮"; String sr = URLEncoder.encode(QUERY); System.out ...

  3. nenu contest2

    http://vjudge.net/vjudge/contest/view.action?cid=54562#overview H  B. Polygons http://codeforces.com ...

  4. [转载]c# OpenFileDialog

    string resultFile = ""; OpenFileDialog openFileDialog1 = new OpenFileDialog();            ...

  5. ReplicaManager之DelayedOperation

    DelayedOperation包括两种:DelayedFetch和DelayedProduce,它们的存在是由Kafka Protocol决定的,而Kafka Protocol是由实际需求决定的…… ...

  6. String 内在分配解析

    1.String类概念 (1)String是final的,不可被继承.public final class String.String是的本质是字符数组char[], 并且其值不可改变.private ...

  7. jquery层居中,点击小图查看大图,弹出层居中代码

    1.层居中 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  8. JavaScript 隐式转换

    javascript 中的怪癖,js运算符隐式类型转换 x + "" //等价于 String(x) + x //等价于 Number(x),也可以写成x-0 !!x //等价于 ...

  9. 关于Model层中Datetime Datetime? 默认值的问题

    DateTime 和 DateTime?前者不允许为空,会有默认值,而DateTime?可以为Null 其他数值型同理!

  10. 移植 FFMPEG-2.2.4 -(编译)

    源码下载:http://www.ffmpeg.org/download.html编译安装: http://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu su ...