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 ...
随机推荐
- SQL配置的坑
我要被自己蠢哭了,新做了一台电脑装SQL sever为了存数据,配置完,突然间发现MSSQLSEVER 不能重新启动,相当于之前的配置,还IP都白弄了.我找原因找了3个小时,后来发现是手欠启动的不该启 ...
- oracle 链接
<properties> <!--配置Hibernate方言 --> <property name="hibernate.dialect" value ...
- 解决Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/cqupt/paging/dao/User.xml
搭建了一个ssm项目,启动报错Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find re ...
- 51单片机小项目电路TwoLed电路图
1.复位电路没有开关,不可控 在电容旁边并联一个开关和10k的电阻支路 2.晶振电路引用的外部晶振, 理论上XTAL2悬空,XTAL1接外部震荡信号 //ProjeceName:TwoLed //wr ...
- install svn server in Ubuntu
1. #安装服务 apt-get install subversionapt-get install libapache2-svnapt-get install apache2apt-get inst ...
- javascript常见的几种事件类型
第一种事件类型:onchange() <body> <select id="sheng" onchange="fn1();"> < ...
- Java 初始 多态
什么是多态 简单的来说就是具有多种形态的能力的特征 package ten; public interface Day1 { public void ring(); } package ten; pu ...
- USG防火墙DHCP设置保留IP地址
在使用disp cur查看当前配置 然后使用undo修改 这样10.0.1.1网段到10.0.1.100之间的IP地址不会分出去
- 集合总结一(ArrayList的实现原理)
一.概述 一上来,先来看看源码中的这一段注释,我们可以从中提取到一些关键信息: Resizable-array implementation of the List interface. Implem ...
- 安装phpssdbadmin
1:先安装nginx+php 参考博文:http://www.cnblogs.com/lemon-le/p/7161356.html 里面有详细的搭建lnmp架构,这里只需参照安装php和ngin ...