UVA Watering Grass
贪心算法。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
struct Node
{
double lx;
double rx;
}node[];
bool cmp(Node a,Node b)
{
return a.lx<b.lx;
}
int main()
{
double n,m,w,l,r;
while(scanf("%lf%lf%lf",&n,&m,&w)!=EOF)
{
int x=,i,j,ans=,ok=;
for(int i=;i<n;i++)
{
scanf("%lf%lf",&l,&r);
if(w/>=r) continue;
double t=(double)sqrt(r*r-((w*w)/4.0));
node[x].lx=l-t;
node[x].rx=l+t;
x++;
}
sort(node,node+x,cmp);
double left=0.0,right=0.0;
if(node[].lx<=)
{
i=;
while(i<x)
{
j=i;
while(j<x && node[j].lx<=left)
{
if(node[j].rx>right)
{
right=node[j].rx;
}
j++;
}
if(i==j) break;
i=j;
ans++;
left=right;
if(left>=m)
{
ok=;
break;
}
}
}
if(ok)printf("%d\n",ans);
else printf("-1\n");
}
return ;
}
UVA Watering Grass的更多相关文章
- UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...
- 10382 - Watering Grass
Problem E Watering Grass Input: standard input Output: standard output Time Limit: 3 seconds n sprin ...
- Watering Grass(贪心)
Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long and w meters ...
- Uva 10382 (区间覆盖) Watering Grass
和 Uva 10020几乎是一样的,不过这里要把圆形区域转化为能够覆盖的长条形区域(一个小小的勾股定理) 学习一下别人的代码,练习使用STL的vector容器 这里有个小技巧,用一个微小量EPS来弥补 ...
- UVa 10382 - Watering Grass
题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...
- 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(区间覆盖)
n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...
- UVA 10382 Watering Grass 贪心+区间覆盖问题
n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...
- uva 10382 - Watering Grass(区域覆盖问题)
Sample Input 8 20 2 5 3 4 1 1 2 7 2 10 2 13 3 16 2 19 4 3 10 1 3 5 9 3 6 1 3 10 1 5 3 1 1 9 1 Sample ...
随机推荐
- 【Codeforces】512C Fox and Dinner
[解析]欧拉筛法,奇偶分析.建二分图,网络流 [Analysis] http://blog.csdn.net/qq574857122/article/details/43453087. 所谓的连通块就 ...
- [Servlet&JSP] HttpSession会话管理
我们能够将会话期间必须共享的资料保存在HttpSession中,使之成为属性.假设用户关掉浏览器接受Cookie的功能.HttpSession也能够改用URL重写的方式继续其会话管理功能. HttpS ...
- mysql-组合查询
一.组合查询 mysql允许执行多个查询(多条select语句),并将结果作为单个查询结果集返回.这些组合查询通常称为并(union)或复合查询(compound query). 有两种情况需要使用组 ...
- ASP.NET Web开发技术的深入总结
[IT168技术]在国内.Net开发这个环境里, 中小型公司.或者大公司但主营业务不是软件开发里面的软件小团队.针对.Net开发者的要求都是十项全能型的全才, 能做的了从前台页面展现到最后数据存储的全 ...
- 单点登录(二)使用Cookie+File实现单点登录登出(附源代码)
上一篇文章<单点登录(一)使用Cookie+File实现单点登录>中,我们实现了单点登录的功能. 本文作为上一篇文章的扩展部分,加入"单点登出"功能. 源代码下载:链接 ...
- nodejs简介
1.Node.js是什么? Node.js不是一种独立的语言,与PHP.java..net即是开发语言也是平台不同,也不是javaScript的框架 jquery,更不是浏览器的库ExtJs,能不与E ...
- POJ 2828 线段树 逆序插入
思路: 1.线段树 逆着插入就OK了 2.块状链表 (可是我并不会写) //By SiriusRen #include <cstdio> #include <cstring> ...
- 《剑指offer》合并两个排序的链表
一.题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 二.输入描述 两个递增排序的链表 三.输出描述 合并成一个递增排序的链表 四.牛客网提供的框 ...
- <Sicily>Pythagorean Proposition
一.题目描述 One day, WXYZ got a wooden stick, he wanted to split it into three sticks and make a right-an ...
- hdu 2647 Reward(拓扑排序+优先队列)
Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he ...