题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1323

题意

长方形l * w,给出长方形中间那条线上n个圆的圆心c和半径r,选取最少数目的圆覆盖长方形,选不了输出-1

思路

明显,算出圆在边上的坐标,然后尽量从左向右扩展就行

感想:

卡题的原因是反射性以为r和w很小,但其实可以很大,所以用double存r

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<double, double> MyPair;
const int MAXN = 1e4 + ;
double c[MAXN];
double r[MAXN];
MyPair myRange[MAXN];
double posmx[MAXN]; int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
int n, l, w;
for (int ti = ;cin>>n>>l>>w; ti++) {
for (int i = ; i < n; i++) {
cin >> c[i] >> r[i];
double gap = (r[i] >= (w / 2.0) ? sqrt(r[i] * r[i] - w * w / 4.0) : -);
myRange[i] = MyPair(c[i] - gap, c[i] + gap);
}
sort(myRange, myRange + n);
bool fl = myRange[].first <= ;
double pos = ;
int ans = ;
for (int i = ; i < n && fl && pos < l; ans++) {
double posNxt = -;
while (i < n && myRange[i].first <= pos) {
posNxt = max(posNxt, myRange[i].second);
i++;
}
if (posNxt <= pos && pos < l) { fl = false; }
else pos = posNxt;
}
if (!fl || pos < l)ans = -;
printf("%d\n", ans);
} return ;
}

UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0的更多相关文章

  1. UVA 10382 Watering Grass 贪心+区间覆盖问题

    n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...

  2. UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】

    UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...

  3. UVA 10382 Watering Grass(区间覆盖,贪心)题解

    题意:有一块草坪,这块草坪长l 米,宽 w 米,草坪有一些喷头,每个喷头在横坐标为 p 处,每个喷头的纵坐标都是(w/2) ,并且喷头的洒水范围是一个以喷头为圆心,半径为 r 米的圆.每次最少需要打开 ...

  4. UVa 10382 Watering Grass (区间覆盖贪心问题+数学)

    题意:有一块长为l,宽为w的草地,在其中心线有n个喷水装置,每个装置可喷出以p为中心以r为半径的圆, 选择尽量少的装置,把草地全部润湿. 析:我个去啊,做的真恶心,看起来很简单,实际上有n多个坑啊,首 ...

  5. UVA 10382 Watering Grass (区间覆盖,贪心)

    问题可以转化为草坪的边界被完全覆盖.这样一个圆形就换成一条线段. 贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur, 从左端点小于等于cur选一个右端点 ...

  6. UVA 10382 Watering Grass(区间覆盖)

    n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...

  7. UVa 10382 - Watering Grass

    题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...

  8. uva 10382 - Watering Grass(区域覆盖问题)

    Sample Input 8 20 2 5 3 4 1 1 2 7 2 10 2 13 3 16 2 19 4 3 10 1 3 5 9 3 6 1 3 10 1 5 3 1 1 9 1 Sample ...

  9. uva 10382 Watering Grass_贪心

    题意:给你个矩形n*m,再给你n个圆的圆心坐标和半径,问最用最少用几个圆把这个矩形覆盖 思路:直接想发现这问题不容易,后来发现可以把圆看做区间(能把矩形面积覆盖),然后这个问题就容易解决了 #incl ...

随机推荐

  1. cocos2d-x 贡献一个oss上传脚本

    平常写前端项目和H5游戏时特别频繁的一个操作就是上传到oss上,特别浪费时间.所以用ali-oss写了一个脚本.配置属性后直接npm run oss就能上传到oss上了.再也不需要手动操作.现在是脚本 ...

  2. C# 并发编程 · 经典实例

    http://www.cnblogs.com/savorboard/p/csharp-concurrency-cookbook.html 异步基础 任务暂停,休眠 异步方式暂停或者休眠任务,可以使用  ...

  3. Vue.js使用Leaflet地图

    参考:https://blog.csdn.net/Joshua_HIT/article/details/72860171 vue2leaflet的demo:https://github.com/KoR ...

  4. C#ImageList和ListView的使用

    一.ImageList  ImageList组件,又称为图片存储组件,它主要用于存储图片资源,然后在控件上显示出来,这样就简化了对图片的管理.ImageList组件的主要属性是Images,它包含关联 ...

  5. 微信OpenID获取

    用户要求在微信端登录一次后,以后不需要再登录.  我的系统是单独的一个网站. 使用MVC的记住密码功能, 如果用户重启,就还是要输入密码,所以需要有一个唯一不变的用来标示用户的ID.  OpenID就 ...

  6. 灵雀云容器PaaS平台助力知名股份制银行金融科技革新

    互联网.科技和金融的碰撞给银行业带来巨大影响.IT技术起初是传统金融提升效率的工具和方法,随着新技术的演进,技术成为驱动变革的核心要素.Fintech金融科技以技术和数据为驱动,用创新的方法改变了金融 ...

  7. Linux基础命令---accept/reject 允许拒绝发送打印请求

    accept accept指令用来设置允许向目标打印机发送打印任务. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.   1.语法      cupsaccept ...

  8. Centos 编译 安装 criu

    下载依赖库 sudo yum install protobuf protobuf-c protobuf-c-devel protobuf-compiler protobuf-devel protobu ...

  9. ListTile

    const ListTile({ Key key, this.leading, // item 前置图标 this.title, // item 标题 this.subtitle, // item 副 ...

  10. P2053 [SCOI2007]修车(费用流)

    P2053 [SCOI2007]修车 顾客平均等待的最小时间$=$等待总时间$/n$ 考虑只有1个技术人员时,$n$辆车等待总时间 $A_1+(A_1+A_2)+(A_1+A_2+A_3)+...+\ ...