画图,每个给出点都有对应区间;先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=;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=;
double temp=-1.0;
for(int i=;i<n;++i){
if(temp<vec[i].l||temp>vec[i].r){
++ans;
temp=vec[i].r;
}
}
printf("%d\n",ans);
}
return ;
}

uva1615 Highway的更多相关文章

  1. UVA-1615 Highway (贪心,区间选点)

    题目大意:有一条沿x轴正方向,长为L的高速公路,n个村庄,要求修建最少的公路出口数目,使得每个村庄到出口的距离不大于D. 题目分析:区间选点问题.在x轴上,到每个村庄距离为D的点有两个(超出范围除外) ...

  2. 【贪心】Highway

    [UVa1615]Highway 算法竞赛入门经典第8章8-11(P255) 题目大意:给定平面上N个点和D,要求在x轴上选出一些点,每个给定的点至少与一个选出的点欧几里得距离<=D 试题分析: ...

  3. luogu题解 UVA1615 【Highway】

    题目链接: https://www.luogu.org/problemnew/show/UVA1615 分析: 首先这里的距离是欧几里得距离而不是曼哈顿距离. 然后我们对于每个点,求出在公路上保持D范 ...

  4. 高速公路(Highway,ACM/ICPC SEERC 2005,UVa1615)

    I think: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <m ...

  5. zoj 3946 Highway Project(最短路 + 优先队列)

    Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar ...

  6. [HihoCoder] Highway 高速公路问题

    Description In the city, there is a one-way straight highway starts from the northern end, traverses ...

  7. Total Highway Distance

    Total Highway Distance 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playing a ...

  8. 基于pytorch实现HighWay Networks之Train Deep Networks

    (一)Highway Networks 与 Deep Networks 的关系 理论实践表明神经网络的深度是至关重要的,深层神经网络在很多方面都已经取得了很好的效果,例如,在1000-class Im ...

  9. Highway Networks

    一 .Highway Networks 与 Deep Networks 的关系 深层神经网络相比于浅层神经网络具有更好的效果,在很多方面都已经取得了很好的效果,特别是在图像处理方面已经取得了很大的突破 ...

随机推荐

  1. 替换一个文件中的内容BAT

    @echo off setlocal enabledelayedexpansion set file=%1set "file=%file:"=%" for %%i in ...

  2. C. Vanya and Scales

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  3. hibernate基础配置文件

    主配置文件 <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC " ...

  4. CF788B Weird journey

    总共有n个节点,m条路径,要求其中m-2条路径走两遍,剩下2条路径仅走一遍,问不同的路径总数有多少,如果仅走一遍的两条边不同则将这两条路径视为不同. 可以把每条边都拆成两条重边,每条边的度数都是偶数了 ...

  5. div里面放img

    div里面放img的时候 会出现包裹不住的情况,这个时候 只要将img { width:100%,height:100%  },就可以解决问题了

  6. python计算代码运行时间的装饰器

    import time def cal_time(func): def wrapper(*args, **kwargs): t1 = time.time() result = func(*args, ...

  7. 机器学习概念之特征选择(Feature selection)

    不多说,直接上干货! .

  8. 百度地图API简单初始化

    <script src="http://api.map.baidu.com/api?key=&v=2.0&ak=youkey"></script& ...

  9. LINUX 文件夹打包

    tar -zcvf /data/www.tar.gz data/www tar -zcvf 打包后生成的文件名全路径 要打包的目录 压缩: 压缩当前的文件夹 zip -r ./xahot.zip ./ ...

  10. Visual Studio Code配置 HTML 开发环境

    Visual Studio Code配置 HTML 开发环境 https://v.qq.com/x/page/l0532svf47c.html?spm=a2h0k.11417342.searchres ...