UVALive 3835:Highway(贪心 Grade D)
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)的更多相关文章
- UVALive 3664:Guess(贪心 Grade E)
vj题目链接 题意: 有n (n<16345)个人,每个人有三个数(小于1000且最多两位小数点),表示答对对应题的得分.规定总分越高的人rank越高.总分相同,id小的rank高.现在知道ra ...
- UVALive 3507:Keep the Customer Satisfied(贪心 Grade C)
VJ题目链接 题意: 知道n(n <= 8e6)个工作的完成所需时间q和截止时间d,你一次只能做一个工作.问最多能做多少工作? 思路: 首先很像贪心.观察发现如下两个贪心性质: 1)一定存在一个 ...
- UVAlive 2911 Maximum(贪心)
Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm ...
- uvalive 2911 Maximum(贪心)
题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...
- UVALive - 4225(贪心)
题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known ...
- UVALive 4850 Installations 贪心
题目链接 题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大 ...
- UVALive 4863 Balloons 贪心/费用流
There will be several test cases in the input. Each test case will begin with a line with three inte ...
- UVALive - 6268 Cycling 贪心
UVALive - 6268 Cycling 题意:从一端走到另一端,有T个红绿灯,告诉你红绿灯的持续时间,求最短的到达终点的时间.x 思路:
- UVALive 4731 dp+贪心
这个题首先要利用题目的特性,先贪心,否则无法进行DP 因为求期望的话,越后面的乘的越大,所以为了得到最小值,应该把概率值降序排序,把大的数跟小的系数相乘 然后这种dp的特性就是转移的时候,由 i推到i ...
随机推荐
- vSphere 6.7 新特性 — 基于虚拟化的安全 (VBS)
https://blogs.vmware.com/china/2018/07/27/vsphere-6-7-%E6%96%B0%E7%89%B9%E6%80%A7-%E5%9F%BA%E4%BA%8E ...
- Java--类初始化
package httpclient.demo; public class StaticTest { public static void main(String[] args) { staticFu ...
- Java中包的基本管理与编译
在写程序的过程中,总会出现代码编译过关,但是项目偏偏报错的情况,遇到几种情况,都在此一一记录,希望以后少走弯路. 1.添加jsp文件的时候,会报错 Multiple annotations found ...
- mysql数据库大规模数据读写并行时导致的锁表问题
问题介绍 最近在给学校做的一个项目中,有一个功能涉及到考核分数问题. 我当时一想,这个问题并不是很难,于是就直接采用了这样的方法:拿着一个表中的数据作为索引,去挨个遍历相关表中的数据,最后经过算分的过 ...
- Linux(CENTOS7) Jdk完整步骤安装
方式一: 直接通过yum安装,这种方式比较方便,下面贴上安装jdk1.8*的命令: -openjdk* -y 上面命令执行完成之后,使用下面命令即可查看是否安装成功: java -version 方式 ...
- openlayers的loaders方式加载
openlayers loaders方式加载 let layerVector = new ol.layer.Vector({ source : new ol.source.Vector({ loade ...
- python paramiko登陆设备
一,单线程 - shell交互 def chan_recv(chan): data = chan.recv(1024) # 收1024数据 sys.stdout.write(data.decode() ...
- VirtualBox虚拟机下Linux CentOS6.9安装增强功能
VirtualBox安装CentOS后,再安装增强功能就可以共享文件夹.粘贴板以及鼠标无缝移动,主要步骤如下: 1.yum -y update 2.yum -y install g++ gcc gc ...
- C盘满了解决办法之hiberfil.sys文件
C盘的hiberfil文件占了很大的空间: 这个是系统的休眠文件,可以通过命令关闭:powercfg -h off [on是打开]
- lower_bound()和upper_bound()用法详解
lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的. lower_bound( begin,end,num):从数组的begin位置到end ...