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 ...
随机推荐
- [Data Structure] Tree - relative
Segment Tree First, try to build the segment tree. lintcode suggest code: Currently recursion recomm ...
- 【转】Win32程序中调用ActiveX控件
#include "stdafx.h" #include <iostream> #include <windows.h> #include <comd ...
- C# 引用类型公共变量的影响
public int[] a =new int[2]; private void button1_Click(object sender, EventArgs e) { bing(a); } priv ...
- Linux下初次使用github
1.安装 1.1 使用yum安装的 命令:$ yum install git git-gui 1.2 生成密钥对,使用ssh-keygen方法 ssh-keygen -t [rsa|dsa],将会生成 ...
- Post Order traverse binary tree using non-recursive way
Process analysis Stack = 5, Push 3, Stack = 5, 3. Pre = 5 Current = 3, Pre = 5, Push 2 to the st ...
- mysql date
date_format(`time`, '%Y-%m-%d %h:%i:%s' ) as time
- 链接属性external的使用
//demo1.c #include<stdio.h> ; //static int x = 10; void print(void) //static void print(void) ...
- python: 文件的读写
#文件的读取.py a=open('test.txt').readline() #只读取文件第一行,保存为字符串格式 b=open('test.txt').read() #读取全部内容,保存为字符串格 ...
- linux4.15.1编译init/mounts报错
AR init/mounts.o arm-linux-ar: illegal option -- T Usage: arm-linux-ar [emulation options] [-]{dmpqr ...
- Python开发 基礎知識 2.變量 ( *arg, **kwargs )
變量 *args 和 **kwargs ( *和**為本體,名稱為通俗的名稱約定 ) *args 用於函式定義. 可將不定數量的參數傳遞給一個函數,傳入函式的引數,會先以Tuple物件收集,再設定給參 ...