VJ题目链接

题意:平面上有n个点,在x轴上放一些点,使得平面上所有点都能找到某个x轴上的点,使得他们的距离小于d。求最少放几个点。

思路:以点为中心作半径为d的圆,交x轴为一个线段。问题转换成用最少的店覆盖所有的线段。经典贪心。按右点从小到大排序,然后从左往右扫,每次选择区间右点就行了。

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; #define N 100100 bool eqs(double a, double b) {
return fabs(a-b) < 1e-;
} struct Seg{
double l, r;
void get(int d) {
int x, y;
scanf("%d%d", &x, &y);
double dx = sqrt(d*d-y*y+0.0);
l = x - dx;
r = x + dx;
}
bool operator < (const Seg &b) const {
if (!eqs(r,b.r)) return r < b.r;
return l < b.l;
}
}seg[N]; int main(){
int l;
while (scanf("%d", &l) != EOF) {
int d;
scanf("%d", &d);
int n;
scanf("%d", &n);
for (int i = ; i < n; i++) {
seg[i].get(d);
}
sort(seg, seg+n); int cnt = ;
double now = -0x3f3f3f3f;
for (int i = ; i < n; i++) {
if (now < seg[i].l) {
now = seg[i].r;
cnt++;
}
}
printf("%d\n", cnt);
}
return ;
}

UVALive 3835:Highway(贪心 Grade D)的更多相关文章

  1. UVALive 3664:Guess(贪心 Grade E)

    vj题目链接 题意: 有n (n<16345)个人,每个人有三个数(小于1000且最多两位小数点),表示答对对应题的得分.规定总分越高的人rank越高.总分相同,id小的rank高.现在知道ra ...

  2. UVALive 3507:Keep the Customer Satisfied(贪心 Grade C)

    VJ题目链接 题意: 知道n(n <= 8e6)个工作的完成所需时间q和截止时间d,你一次只能做一个工作.问最多能做多少工作? 思路: 首先很像贪心.观察发现如下两个贪心性质: 1)一定存在一个 ...

  3. UVAlive 2911 Maximum(贪心)

    Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm ...

  4. uvalive 2911 Maximum(贪心)

    题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...

  5. UVALive - 4225(贪心)

    题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known ...

  6. UVALive 4850 Installations 贪心

    题目链接  题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大 ...

  7. UVALive 4863 Balloons 贪心/费用流

    There will be several test cases in the input. Each test case will begin with a line with three inte ...

  8. UVALive - 6268 Cycling 贪心

    UVALive - 6268 Cycling 题意:从一端走到另一端,有T个红绿灯,告诉你红绿灯的持续时间,求最短的到达终点的时间.x 思路:

  9. UVALive 4731 dp+贪心

    这个题首先要利用题目的特性,先贪心,否则无法进行DP 因为求期望的话,越后面的乘的越大,所以为了得到最小值,应该把概率值降序排序,把大的数跟小的系数相乘 然后这种dp的特性就是转移的时候,由 i推到i ...

随机推荐

  1. 关于debug模式下对象toString报空指针的问题。Method threw 'java.lang.NullPointerException' exception. Cannot evaluate cn.gooday.jsh.service.common.dto.RestControllerResult.toString()

    这个如果debug的时候可以一步步走到正常return或者运行的时候有正确返回值.说明代码是没问题的. 出现这个的原因是dto对象里有一些字段查出来是空的,或者这个字段本来在dto里就是冗余字段. 因 ...

  2. Python D9 学习

    Python 设置环境 当安装好Python 后 在计算机的属性里面   高级语言设置  环境变量. 环境变量里面的path  更改为Python的 树目录  可以从计算机直接下达命令 打开Pytho ...

  3. 01 语言基础+高级:1-3 常用API第一部分_day08【String类、static、Arrays类、Math类】

    day08[String类.static.Arrays类.Math类] String类static关键字Arrays类Math类 教学目标能够使用String类的构造方法创建字符串对象能够明确Stri ...

  4. java 利用管道实现线程间通信

    package com.lb; import java.io.IOException;import java.io.PipedInputStream;import java.io.PipedOutpu ...

  5. Data总结

    getTime() 方法可返回距 1970 年 1 月 1 日之间的毫秒数 var d = new Date(); var n = d.getTime(); //一长串数字

  6. Python—使用Json序列化Datetime类型

    import json from datetime import datetime, date """ str,int,list,tuple,dict,bool,None ...

  7. springboot配置多个yml文件

    新接触了springboot项目,yml一大堆,启动不知道用的哪个,各种百度后: <profiles> <profile> <id>dev</id> & ...

  8. c++语法(3)

    子类覆盖父类的成员函数: #include "stdafx.h" #include "iostream" class CAnimal { protected: ...

  9. JS中的let变量

    介绍JS中的let变量: let允许你声明一个作用域被限制在块级中的变量.语句或者表达式.在Function中局部变量推荐使用let变量,避免变量名冲突. 作用域规则 let 声明的变量只在其声明的块 ...

  10. JS 特效三大系列总结

    一. offset系列 1. offset系列的5个属性 1. offsetLeft : 用于获取元素到最近的定位父盒子的左侧距离 * 计算方式: 当前元素的左边框的左侧到定位父盒子的左边框右侧 * ...