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. Fiddler 断点命令

    Request 断点:bpu /priceCalculate 清除命令:bpu Response 断点:bpafter /priceCalculate 清除命令:bpafter

  2. web项目servlet&jsp包失效问题

    今天偶然遇到这样的一个问题,故做个总结. javaee开发只用到serlet和jsp两个包.而sun提供的jdk只是javase部分的包,对于se部分只提供了规范,而包由容器给出. 由于自己在新建好一 ...

  3. 【MySQL参数】- query_cache_type

    MySQL为什么要关闭查询缓存 https://blog.csdn.net/liqfyiyi/article/details/50178591 Query cache的优化方法 https://blo ...

  4. [原]排错实战——VS清空最近打开的工程记录

    原脚本how-toprocess monitorsysinternalsvsvisual studiovs2017vs2019注册表 缘起 vs有一个功能 -- 在起始页会显示最近打开的工程列表,方便 ...

  5. vscode Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

    vscode 连接 mysql 时出现这个错误 alter user 'root'@'localhost' identified with mysql_native_password by 'pass ...

  6. [Scoi2016]背单词(trie+贪心)

    题意:重新解释一下题意吧(题意晦涩难懂) 给定n个单词,你可以按照顺序学习,当学习这一单词时,这个单词是第x个要学习的单词,需要的代价分三类: 1.若存在其他单词是其后缀没被学习,则代价为n2 2.若 ...

  7. SLAM领域资源链接

    半闲居士高翔博客: https://www.cnblogs.com/gaoxiang12/ 视觉大佬冯兵博客: http://www.fengbing.net/ SLAMCN http://www.s ...

  8. C语言实现整数转字符串

    #include <stdio.h> void intToString(int N,char arr[]){ //仅支持有符号4字节的int类型,范围-2147483648 - 21474 ...

  9. Long型转ZonedDateTime型

    /** * 将Long类型转化成0 * @author yk * @param time * @return */public static ZonedDateTime toZonedDateTime ...

  10. CodeForces 992C Nastya and a Wardrobe(规律、快速幂)

    http://codeforces.com/problemset/problem/992/C 题意: 给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减 ...