题意:对于长为L,宽为W的矩形草地,需要对它进行浇水,总共有n个水龙头,给每个水龙头的浇水半径,和位置.求覆盖整个草地需要的最小水龙头数量.

如图,把浇水的面积转换成矩形,然后就和区间覆盖一样了,直接贪心

WA了很多次, w/2 >= r这里,w一直用整数,一直wa

#include"pch.h"
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip>
#include<bitset>
#include"math.h"
namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string;
using std::sort;
using std::priority_queue;
using std::greater;
using std::vector;
using std::swap;
using std::stack;
using std::bitset; class Input
{
public:
double s = ;
double e = ;
}; constexpr int N = ; int n, l, w;
Input ins[N]; int min = ; bool cmp(const Input& in1, const Input& in2)
{
return in1.s < in2.s;
} int flag = ;
void search()
{
double curL = ;
double curR = ;
for (int i = ;i < n; )
{
int j = i;
while (j < n && ins[j].s <= curL)
{
if (ins[j].e >= curR)
curR = ins[j].e;
++j;
}
if (i == j)
break;
i = j;
curL = curR;
++min;
if (curL >= l)
{
flag = ;
break;
} } } void solve()
{
while (cin >> n >> l >> w)
{
double p, r;
min = ; flag = ;
int total = ;
int isok = ;
for (int i = ;i < n;i++)
{
cin >> p >> r;
if (w*1.0 / >= r)
continue;
double x = sqrt((r*r - (w*w*0.25)));
Input in;
in.s = p - x;
in.e = p + x;
if (in.s < )
in.s = ;
ins[total++] = in;
if (in.e >= l)
isok = ;
}
if (!isok)
{
cout << "-1" << endl;
continue;
} n = total;
sort(ins, ins + n, cmp);
search();
if (flag == )
cout << - << endl;
else
cout << min << endl;
}
} }; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return ;
}

uva-10382-贪心的更多相关文章

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

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

  2. UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

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

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

  4. UVa 10382 喷水装置(贪心)

    https://vjudge.net/problem/UVA-10382 题意: 有一个长为l,宽为w的草坪,在其中心线不同位置有n个点状的喷水装置,喷水坐标为p,喷水半径为r.求喷到所有草坪的最少喷 ...

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

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

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

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

  7. uva 10382 Watering Grass_贪心

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

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

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

  9. 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...

  10. UVA 11389(贪心问题)

    UVA 11389 Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description II  ...

随机推荐

  1. 超简单的实现wordcount

    worcount1.0,源码参见GitHub:https://github.com/18382271904/spring_lee_flag.git

  2. 基于FPGA的1553B通信模块的设计(转)

    reference:http://www.21ic.com/app/eda/201808/798483.htm https://www.milstd1553.com/ [导读] 摘 要: 提出一种将F ...

  3. Java容器解析系列(4) ArrayList Vector Stack 详解

    ArrayList 这里关于ArrayList本来都读了一遍源码,并且写了一些了,突然在原来的笔记里面发现了收藏的有相关博客,大致看了一下,这些就是我要写的(╹▽╹),而且估计我还写不到博主的水平,这 ...

  4. linux do{} while(0)

    do{}while(0) 在linux中,经常会看到do{}while(0)这样的语句,许多人开始都会疑惑,认为do{}while(0)毫无意义,因为它只会执行一次,加不加do{}while(0)效果 ...

  5. MySQL配置文件my.ini或my.cnf的位置

    1.Windows下MySQL的配置文件是my.ini,一般会在安装目录的根目录. 2.Linux下MySQL的配置文件是my.cnf,一般会放在/etc/my.cnf,/etc/mysql/my.c ...

  6. 深入理解Java中的synchronized锁重入

    问题导入:如果一个线程调用了一个对象的同步方法,那么他还能不能在调用这个对象的另外一个同步方法呢? 这里就是synchronized锁重入问题. 一.synchronized锁重入 来看下面的代码: ...

  7. .net webapi跨域方法整理

    方法一 在Web.Config里面加上了配置信息: <httpProtocol> <customHeaders> <add name="Access-Contr ...

  8. h5 js判断是安卓还是ios设备,跳转到对应的下载地址

    /*ios和安卓跳转 js*/$(function(){ var u = navigator.userAgent; var ua = navigator.userAgent.toLowerCase() ...

  9. alpha冲刺(2/10)

    前言 队名:旅法师 作业链接 队长博客 燃尽图 会议 会议照片 会议内容 陈晓彬(组长) 今日进展: 召开会议 安排任务 博客撰写 构建之法的阅读 问题困扰: 分配任务,还是不熟练,对后台不熟悉,不知 ...

  10. yii2 自带分页使用

    //下面为控制器层的方法内容use \yii\db\Query;use \yii\data\Pagination; //方法内容        $query=new Query();//from为自带 ...