参考:  

https://blog.csdn.net/shuangde800/article/details/7828675

https://www.cnblogs.com/haoabcd2010/p/6171794.html?utm_source=itdadao&utm_medium=referral

 #include <iostream>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; struct node
{
double L;
double R;
}a[]; bool cmp(node a, node b)
{
return a.R > b.R;
} void sort_node(int n)
{
for (int i=;i<n;i++)
{
int k=i;
for (int j=i+;j<n;j++)
{
if (a[j].R>a[k].R)
k=j;
}
swap(a[k],a[i]);
}
} int main()
{
int n;
double length, wide;    // 都定义为double类型,因为使用勾股定理的时候肯定会算出小数
double center, radius; // center为圆心,radius为半径
double t;
while(scanf("%d%lf%lf", &n, &length, &wide) != EOF)
{
for(int i = ; i < n; ++i)
{
cin >> center >> radius;
t = sqrt(radius*radius - (wide/2.0)*(wide/2.0));
a[i].L = center - t;
a[i].R = center + t;
} //sort(a, a+n, cmp); 快排不知道为什么不能AC
sort_node(n); double border = ;
int cnt = ;
while(border < length)  // 此类型题目的固定套路
{
int i;
for(i = ; i < n; ++i)
{
if(a[i].L <= border && a[i].R > border)
{
border = a[i].R;
cnt++;
break;
}
} if(i == n) // 如果i==n,说明遍历完了这n个区间,仍然没有找到符合条件的,即不能完全覆盖
break;
} if(border < length)
cout << - << endl;
else
cout << cnt << endl;
} return ;
}

Watering Grass (贪心,最小覆盖)的更多相关文章

  1. Watering Grass(贪心)

    Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long and w meters ...

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

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

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

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

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

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

  5. 10382 - Watering Grass

    Problem E Watering Grass Input: standard input Output: standard output Time Limit: 3 seconds n sprin ...

  6. Watering Grass(贪心算法)

    给定一条草坪.草坪上有n个喷水装置.草坪长l米宽w米..n个装置都有每个装置的位置和喷水半径..要求出最少需要几个喷水装置才能喷满草坪..喷水装置都是装在草坪中间一条水平线上的. n sprinkle ...

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

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

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

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

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

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

随机推荐

  1. 一个WEB网站高并发量的解决方案

    一个小型的网站,可以使用最简单的html静态页面就实现了,配合一些图片达到美化效果,所有的页面均存放在一个目录下,这样的网站对系统架构.性能的要求都很简单.随着互联网业务的不断丰富,网站相关的技术经过 ...

  2. 2019-8-26-当-ASP.NET-Core-链接找不到时可能的原因

    title author date CreateTime categories 当 ASP.NET Core 链接找不到时可能的原因 lindexi 2019-08-26 18:52:28 +0800 ...

  3. 复制字符串 _strdup _wcsdup _mbsdup

    Duplicate strings.函数定义: char *_strdup( const char *strSource ); wchar_t *_wcsdup( const wchar_t *str ...

  4. windows API 第八篇 _tcsicmp _stricmp _wcsicmp _mbsicmp

    这些函数都是比较字符串小写的,忽略大写,出入的字符串都将按照小写比较Perform a lowercase comparison of strings. 函数原型: int _stricmp( con ...

  5. [Swoole系列入门教程 4] 定时器与心跳demo

  6. hdu2516

    hdu2516斐波那契博弈,也是一堆博弈的一种,第一个人第一次可以拿任意多,但是不能取完,第二个人拿至少一个,但不能超过上一个人拿的两倍 #include<iostream> #inclu ...

  7. PHP--时间搜索插件封装

    /** * 时间搜索插件封装 * anthor qinpeizhou * @param $timeset 时间格式 * @param $time sql语句中所需要搜索的time字段名称 * @par ...

  8. Windows 10专业版激活(附激活码)

    安全密钥:BT6TH-FN8VP-6WGCK-6BM9R-MWRDB(使用有效,在物理机,虚拟机都激活了一次) 六一八期间自己买了配件第一次组了台式机,系统是在123pe下的原版win10,装好机器之 ...

  9. 通过Angular-cli创建新项目

    前提:已经安装Git 方法一:(推荐) 1.在需要创建项目的文件夹中右键打开 Git Bush Here ,在此输入  ng new ‘项目名’  --skip-install   (如下my-app ...

  10. 解决CSocket高数据传输问题

    这个是自己项目中发现的问题,所以这个不一定适用于你的. 仅供参考. 头文件: ESSocket.h // ESSocket.h : header file // #ifndef ESSOCKET_H ...