参考:  

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. Python学习day12-函数基础(2)

    <!doctype html>day12博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { pos ...

  2. vue 组件内引入外部在线js、css

    参考:https://blog.csdn.net/u010881899/article/details/80895661 例:引入element-ui js: mounted() { const oS ...

  3. springMVC和springBoot区别

    Spring MVC是什么?(1)Spring MVC是Spring提供的一个强大而灵活的模块式web框架.通过Dispatcher Servlet, ModelAndView 和 View Reso ...

  4. WIN32_FIND_DATA 详细结构(附循环读取文件代码)

    //去除路径最后多余的斜杠和反斜杠 std::string TrimPath(std::string path) { //string test3("内容"); 使用引用字符数组作 ...

  5. redis-cli启动问题

    首先需要找到redis的所在目录,然后将redis.conf复制到/etc/redis.conf 另外需要将redis.conf文件中的 daemonize no 设置为 daemonize yes. ...

  6. DFS-深度优先搜索与BFS-广度优先搜索

    1.DFS DFS是一个递归过程.(类似于二叉树的前序遍历) 参考:深度优先搜索(Depth-First-Search)精髓 2.BFS 可以理解为按层遍历,借助队列结构来实现.(类似于二叉树的层次遍 ...

  7. PAT甲级——A1012 The Best Rank

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  8. 使用MySQL会话变量实现窗口函数

    一.MySQL窗口函数 (1) 序号函数 row_number()在相等的两条记录上随机排序,但序号按照1.2递增,然后后面的序号继续递增为3,中间不会产生序号间隙: rank()/dense_ran ...

  9. mysqldump mysql数据库导出命令

    mysqldump -u用户名 -p密码 数据库名 > 导出的文件名 例如: mysqldump -uroot -p123456 test > /var/test.sql 如果要压缩就用管 ...

  10. 只要三步!阿里云DLA帮你处理海量JSON数据

    概述 您可能有大量应用程序产生的JSON数据,您可能需要对这些JSON数据进行整理,去除不想要的字段,或者只保留想要的字段,或者仅仅是进行数据查询. 那么,利用阿里云Data Lake Analyti ...