题目描述有些坑。。

题意:

  有一条高速公路在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. Sublime Text 2 入门

    SublimeText 2 的介绍视频: http://player.youku.com/player.php/partnerid/XOTcy/sid/XMzU5NzQ5ODgw/v.swf   以下 ...

  2. TCP协议三次握手、四次断开 过程分析

    建立TCP连接的过程需要进行三次信息交换,通常称为“三次握手”,示意图如下:

  3. 例题-Quota 实作:

    假设这五个用户均需要进行磁盘配额限制,每个用户的配额为 2GB (hard) 以及 1.8GB (soft),该如何处理? 答: 这一题实作比较难,因为必须要包括文件系统的支持.quota 数据文件建 ...

  4. ORA-06550:line 1,column 7;PLS-00201:indentifer '存储过程' must be declared;...PL/SQL Statement ignored 问题

    前段时间由于修改SMES系统,出现了一个问题. ORA-06550:line 1,column 7;PLS-00201:indentifer '存储过程' must be declared;...PL ...

  5. axure7.0 汉化包下载

    下载地址:http://files.cnblogs.com/files/feijian/axure7.0%E4%B8%AD%E6%96%87%E8%AF%AD%E8%A8%80%E6%B1%89%E5 ...

  6. Android开发应用异步检查更新代码

    开发环境:android studio    sdk 4.0及以上 场景:用户点击检查更新按钮进行检查服务器版本号,若有新版本则进行下载更新.异步检测版本号 package com.example.q ...

  7. Java7 新特性 switch 可以使用String

    今天和大家分享下 在java7中可以使用String 作为switch 中的参数. 原来在java7之前,switch只能去接收一个 byte.char.short.int 类型 现在在java7中 ...

  8. Mac OS X中MacPorts的安装使用备忘

    Mac下面除了用dmg.pkg来安装软件外,比较方便的还有用MacPorts来帮助你安装其他应用程序,跟BSD中的ports道理一样.MacPorts就像apt-get.yum一样,可以快速安装些软件 ...

  9. ssh 内在溢出

    相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题,这个问题曾困扰了我很长时间,随着解决各类问题经验的积累以及对问题根源的探索,终于有了一个比较深入的认识. 在解决j ...

  10. Unity3d 接入 移动MM支付SDK(2.3) 全攻略

    原地址:http://blog.csdn.net/dingxiaowei2013/article/details/26842177 先将例程运行起来 下载例程(csdn积分不够上传不了,只能用百度网盘 ...