画图,每个给出点都有对应区间;先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. registerWithTouchDispatcher 注册单点触摸事件

    Doc: If isTouchEnabled, this method is called onEnter. Override it to change the way CCLayer receive ...

  2. CoreGpaphics

    CoreGpaphics基本应用 CGAffineTransformMake开头的函数 是基于最初始的位置来变化的 带有CGAffineTransform参数是基于CGAffineTransform的 ...

  3. spring+mybatis 多数据源整合--temp

    <!-- 数据源配置 -->   <bean id="ds1" class="org.apache.commons.dbcp.BasicDataSour ...

  4. 使用CompletableFuture+ExecutorService+Logback的多线程测试

    1. 环境 Java: jdk1.8.0_144 2. 背景 Java多线程执行任务时,Logback输出的主线程和各个子线程的业务日志需要区分时,可以根据线程池和执行的线程来区分,但若要把它们联系起 ...

  5. kubeadm安装Kubernetes13.1集群-三

    环境: master: 192.168.3.100 node01: 192.168.3.101 node02: 192.168.3.102 关闭所有主机防火墙,selinux: 配置主机互信: mas ...

  6. Unity脚本打包android工程

    using UnityEngine; using System.Collections; using UnityEditor; public class NewBehaviourScript : Ed ...

  7. python __builtins__ type类 (69)

    69.'type', 返回对象类型 class type(object) | type(object_or_name, bases, dict) | type(object) -> the ob ...

  8. python 子类调用父类成员的方法

    1.直接写类名调用: parent_class.parent_attribute(self) class Animal(): def __init__(self, name): self.name = ...

  9. python 迭代器 Iterator

    一.可迭代对象定义 可以直接作用于for循环的数据类型有以下几种: 一类是集合数据类型,如list.tuple.dict.set.str.bytes.bytearray等: 一类是generator, ...

  10. 一篇文章搞定面试中的二叉树题目(java实现)

    最近总结了一些数据结构和算法相关的题目,这是第一篇文章,关于二叉树的. 先上二叉树的数据结构: class TreeNode{ int val; //左孩子 TreeNode left; //右孩子 ...