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 ...
随机推荐
- 使用GitHub+Hexo搭建个人博客
title: CozyMo date: 2019-12-28 16:01:29 tags: 书写 前言:搭建博客要自己打代码吗? 开始动手:搭建博客的步骤 个性化:更换主题!! 写博客:初识 mark ...
- elasticsearch-填坑
1.分页参数 ,start=(page-1)*size 2.高亮字段结果的处理方式 3.float类型参数从map中取出用double接收 4.结果封装需手动封装 package com.search ...
- mysql 5.6 cmake的安装
# cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDI ...
- softmax和分类模型
softmax和分类模型 内容包含: softmax回归的基本概念 如何获取Fashion-MNIST数据集和读取数据 softmax回归模型的从零开始实现,实现一个对Fashion-MNIST训练集 ...
- Python与mongo交互
# 导入模块 import pymongo # 连接MongoDB数据库 conn = pymongo.MongoClient('localhost', 27017) # 建库 db = conn.g ...
- PAT Advanced 1132 Cut Integer (20) [数学问题-简单数学]
题目 Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long ...
- C/C++ 取整函数ceil(),floor()
使用floor函数.floor(x)返回的是小于或等于x的最大整数.如: floor(10.5) == 10 floor(-10.5) == -11 使用ceil函数.ceil(x)返回 ...
- Python 中 JSON和dict的转换,json的使用
一. 基础语法 在Python 的 json库中,共有四个方法.分别是: json.load() # 从文件中加载 json.loads() # 数据中加载 json.dump() # 转存到文件 j ...
- TextBox换行C#文本框换行.net文本框换行textarea换行
在TextBox中输入的内容,显示的时候如果用lable显示,无法换行 可以使用TextBox输入,然后也使用TextBox 显示,这样换行输入的内容,显示的时候也可以换行.显示的时候可以设置一下控件 ...
- Linux介绍,基本命令