uva-10382-贪心
题意:对于长为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-贪心的更多相关文章
- UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...
- UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA 10382 Watering Grass(区间覆盖,贪心)题解
题意:有一块草坪,这块草坪长l 米,宽 w 米,草坪有一些喷头,每个喷头在横坐标为 p 处,每个喷头的纵坐标都是(w/2) ,并且喷头的洒水范围是一个以喷头为圆心,半径为 r 米的圆.每次最少需要打开 ...
- UVa 10382 喷水装置(贪心)
https://vjudge.net/problem/UVA-10382 题意: 有一个长为l,宽为w的草坪,在其中心线不同位置有n个点状的喷水装置,喷水坐标为p,喷水半径为r.求喷到所有草坪的最少喷 ...
- UVa 10382 Watering Grass (区间覆盖贪心问题+数学)
题意:有一块长为l,宽为w的草地,在其中心线有n个喷水装置,每个装置可喷出以p为中心以r为半径的圆, 选择尽量少的装置,把草地全部润湿. 析:我个去啊,做的真恶心,看起来很简单,实际上有n多个坑啊,首 ...
- UVA 10382 Watering Grass (区间覆盖,贪心)
问题可以转化为草坪的边界被完全覆盖.这样一个圆形就换成一条线段. 贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur, 从左端点小于等于cur选一个右端点 ...
- uva 10382 Watering Grass_贪心
题意:给你个矩形n*m,再给你n个圆的圆心坐标和半径,问最用最少用几个圆把这个矩形覆盖 思路:直接想发现这问题不容易,后来发现可以把圆看做区间(能把矩形面积覆盖),然后这个问题就容易解决了 #incl ...
- UVA 10382 Watering Grass 贪心+区间覆盖问题
n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...
- 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...
- UVA 11389(贪心问题)
UVA 11389 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description II ...
随机推荐
- ui学习心得
软工课上我分配的任务是界面设计,但是对于初期一个ps从没接触的人来说我觉得还是有点困难,所以要从头学起. PS的功能是什么呢?对于业余爱好者来说,主要还是做一些简单的处理照片.绘图.设计一些皮肤等, ...
- go web framework gin 路由表的设计
在上一篇go web framework gin 启动流程分析这一篇文章中,我分析了go gin启动的过程,在这一篇文章中我将继续上面的分析,讨论gin 中路由表是如何设计的? 首先查看engine. ...
- python基础08_set集合
关于前几次课的回顾: #!/usr/bin/env python # coding:utf-8 ## 字符串 数字 列表 元组 字典 ## 可变:列表 字典 ## 不可变:字符串, 数字, 元组 na ...
- ::WritePrivateProfileString()的用法,以及GetPrivateProfileString的用法注意事项
WritePrivateProfileString(_T("Section1"),_T("Field1"),Field,savePath); 函数说明,这是在写 ...
- php查询快递的类
<?php/** * Express.class.php 快递查询类 * * @copyright widuu * @license ...
- vscode 插件推荐 - 献给所有前端工程师(更新与2018.8.1)
VScode现在已经越来越完善.性能远超Atom和webstorm,你有什么理由不用它?在这里,我会给你们推荐很多实用的插件,让你对 vscode 有更深刻的体会,渐渐地你就会知道它有多好用. 走马观 ...
- CentOS7 cannot find a valid baseurl for repo base
找到文件夹: cd /etc/sysconfig/network-scripts/ 然后找ifcfg 开头的文件,挨个打开 里面有下面那些代码前三行的就是,添加后面DNS两行,保持并退出,然后继续执行 ...
- JDBC driver连接MySQL运行报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than
出错原因: 因为安装mysql的时候时区设置的不正确. mysql默认的是美国的时区,而我们中国大陆要比他们迟8小时,采用GMT+8:00格式. 也就是说是数据库和系统时区差异所造成的. 验证:运行c ...
- alpha冲刺(3/10)
前言 队名:旅法师 作业链接 队长博客 燃尽图 会议 会议照片 会议内容 陈晓彬(组长) 今日进展: 召开会议 安排任务 博客撰写 制定计划 问题困扰: 前后端的交互沟通有点缺失,以至后端进度很慢,需 ...
- 百度地图 JavaScript API
最近有点懒 项目结尾了 完了好长时间 没有去总结项目中的问题 想了下还是写写吧 这是一个关于百度地图的 网页展示 <!DOCTYPE html><html><head ...