题意:对于长为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. Java基础-常用工具类(二)

    Scanner 类 java.util.Scanner 是 Java5 的新特征,我们可以通过 Scanner 类来获取用户的输入. 通过 Scanner 类的 next() 与 nextLine() ...

  2. 远程链接 aws Windows Server 2016 Base Nano

    第一次接触Windows Server 2016 Base Nano,平时工作中或者自己私下使用win的服务器都是带桌面版本的 而这次在aws一不小心开了一台Nano服务,刚开始我都不知道这个是什么玩 ...

  3. 10--Python入门--异常处理

    在程序编写过程中,难免会有一些错误.python中有一些语句可以处理这些异常或者错误,使得程序能够运行,且识别到错误的位置 try..except函数,java中是try catch 在下面的例子中, ...

  4. React-Native新列表组件FlatList和SectionList学习 | | 联动列表实现

    React-Native在0.43推出了两款新的列表组件:FlatList(高性能的简单列表组件)和SectionList(高性能的分组列表组件). 从官方上它们都支持常用的以下功能: 完全跨平台. ...

  5. git 本地重命名文件夹大小写并提交到远程分支

    git branch 查看本地分支 git branch -a 查看本地 本地分支可直接切换:git checkout name 进入正题: 1.文件夹备份 2.git config core.ign ...

  6. 深入理解Java并发synchronized同步化的代码块不是this对象时的操作

    本文仅仅是为了说明synchronized关键字同步的是对象不是方法,列子的确有失偏颇. 一.明确一点synchronized同步的是对象不是方法也不是代码块  我有关synchronized同步的是 ...

  7. JDBC ---获取数据字段 -- 转成map

    getConn = JdbcDataBaseUtil.getConnection(user,pwd,serverUrl,mysqDriver); //建立一个结果集,用来保存查询出来的结果 Resul ...

  8. HBuilder设置沉浸式状态栏显示效果

    1:在[manifest.json]文件中,在[plus-->distribute--> apple]下加上[ "UIReserveStatusbarOffset":f ...

  9. Python导入jar包

    一.环境准备 1.Python 3.6 64位+jre 64位+win64位(jre和Python位数一致) 2.安装jpype,安装的时候输入 pip install jpype1 2.1安装提示e ...

  10. SQL-记录修改篇-008

    修改记录: update table_name  as  a set  a.type = ‘青年' where a.age>18  and  a.age<40 解释:将表中age字段大于1 ...