NYOJ 12:喷水装置(二)(贪心,区间覆盖问题)
12-喷水装置(二)
- 内存限制:64MB 时间限制:3000ms 特判: No
- 通过数:28 提交数:109 难度:4
题目描述:
有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的喷水装置,每个喷水装置i喷水的效果是让以它为中心半径为Ri的圆都被润湿。请在给出的喷水装置中选择尽量少的喷水装置,把整个草坪全部润湿。
输入描述:
第一行输入一个正整数N表示共有n次测试数据。
每一组测试数据的第一行有三个整数n,w,h,n表示共有n个喷水装置,w表示草坪的横向长度,h表示草坪的纵向长度。
随后的n行,都有两个整数xi和ri,xi表示第i个喷水装置的的横坐标(最左边为0),ri表示该喷水装置能覆盖的圆的半径。输出描述:
每组测试数据输出一个正整数,表示共需要多少个喷水装置,每个输出单独占一行。
如果不存在一种能够把整个草坪湿润的方案,请输出0。样例输入:
2
2 8 6
1 1
4 5
2 10 6
4 5
6 5样例输出:
1
2思路
因为所有的喷水装置都在横向中心线上,所以可以利用圆与草坪边界的交点来转换成区间覆盖问题
区间覆盖问题的详解:https://blog.csdn.net/chenguolinblog/article/details/7882316
AC代码
/*
* @Author: WZY
* @School: HPU
* @Date:   2018-10-20 15:19:19
* @Last Modified by:   WZY
* @Last Modified time: 2018-10-20 17:09:48
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#include <time.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
#define bug cout<<"---------"<<endl
#define debug(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<"\n"
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
struct wzy
{
	double l,r;
}p[maxn];
double x[maxn],r[maxn];
bool cmp(wzy u,wzy v)
{
	if(u.l==v.l)
		return u.r>v.r;
	return u.l<v.l;
}
inline double MAX(double a,double b)
{
	return a>b?a:b;
}
inline double MIN(double a,double b)
{
	return a<b?a:b;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	#ifndef ONLINE_JUDGE
	    freopen("in.txt", "r", stdin);
	    freopen("out.txt", "w", stdout);
	    double _begin_time = clock();
	#endif
	int t;
	int n,w,h;
	cin>>t;
	while(t--)
	{
		cin>>n>>w>>h;
		double res=h/2.0;
		double _;
		for(int i=0;i<n;i++)
		{
			cin>>x[i]>>r[i];
			if(r[i]<=res)
				_=0.0;
			else
				_=sqrt(r[i]*r[i]*1.0-res*res*1.0);
			p[i].l=x[i]-_;
			p[i].r=x[i]+_;
		}
		sort(p,p+n,cmp);
		int ans=0;
		double vis=0.0;
		double __;
		for(int i=0;i<n;i++)
		{
			if(p[i].l<=vis)
			{
				__=p[i].r;
				while(p[i].l<=vis)
				{
					__=MAX(p[i].r,__);
					i++;
					if(i==n)
						break;
				}
				vis=__;
				i--;
				ans++;
			}
			if(vis>=w)
				break;
		}
		if(vis>=w)
			cout<<ans<<endl;
		else
			cout<<0<<endl;
	}
	#ifndef ONLINE_JUDGE
	    double _end_time = clock();
	    printf("time = %lf ms.", _end_time - _begin_time);
	#endif
	return 0;
}NYOJ 12:喷水装置(二)(贪心,区间覆盖问题)的更多相关文章
- nyoj 12——喷水装置二——————【贪心-区间覆盖】
		喷水装置(二) 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的 ... 
- 高效算法——E - 贪心-- 区间覆盖
		E - 贪心-- 区间覆盖 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/E 解题思路: 贪心思想, ... 
- 【题解】Cut the Sequence(贪心区间覆盖)
		[题解]Cut the Sequence(贪心区间覆盖) POJ - 3017 题意: 给定一大堆线段,问用这些线段覆盖一个连续区间1-x的最小使用线段的数量. 题解 考虑一个这样的贪心: 先按照左端 ... 
- 基于贪心算法的几类区间覆盖问题 nyoj 12喷水装置(二)  nyoj 14会场安排问题
		1)区间完全覆盖问题 问题描述:给定一个长度为m的区间,再给出n条线段的起点和终点(注意这里是闭区间),求最少使用多少条线段可以将整个区间完全覆盖 样例: 区间长度8,可选的覆盖线段[2,6],[1, ... 
- NYOJ 12 喷水装置(二)
		pid=12">喷水装置(二) 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n( ... 
- 南阳OJ-12-喷水装置(二)贪心+区间覆盖
		题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=12 题目大意: 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有 ... 
- UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
		UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ... 
- 51nod 1091 线段的重叠【贪心/区间覆盖类】
		1091 线段的重叠 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 X轴上有N条线段,每条线段包括1个起点和终点.线段的重叠是这样来算的,[10 2 ... 
- UVA 10382 Watering Grass 贪心+区间覆盖问题
		n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ... 
- B. Heaters  思维题 贪心 区间覆盖
		B. Heaters 这个题目虽然只有1500的分数,但是我还是感觉挺思维的,我今天没有写出来,然后看了一下题解 很少做这种区间覆盖的题目,也不是很擅长,接下来讲讲我看完题解后的思路. 题目大意是:给 ... 
随机推荐
- python中的包
- java集合类,详解
			集合详解 1.1HashSet HashSet是Set接口的一个子类,主要的特点是:里面不能存放重复元素,而且采用散列的存储方法,所以没有顺序.这里所说的没有顺序是指:元素插入的顺序与输出的顺序不一致 ... 
- python django 访问static静态文件
			settings 文件配置: STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'),)PROJEC ... 
- ASP.Net MVC(1) 之走进MVC
			一.MVC三层架构: mvc三层架构,大家都比较熟悉了,这里再介绍一下.Mvc将应用程序分离为三个部分: Model:是一组类,用来描述被处理的数据,同时也定义这些数据如何被变更和操作的业务规则.与数 ... 
- Ubuntu 16.04 中安装谷歌 Chrome 浏览器
			http://jingyan.baidu.com/article/335530da98061b19cb41c31d.html 根据教程安装成功!! http://askubuntu.com/quest ... 
- Dom方法,解析XML文件
			Dom方法,解析XML文件的基本操作 package com.demo.xml.jaxp; import java.io.IOException; import javax.xml.parsers.D ... 
- new_images
			/home/westward/Pictures/Screenshot from 2017-03-19 20:23:55.png 
- day17 面向对象-成员
			今日主要学习了: 1 .成员 2. 变量 3. 方法 4.属性 5.私有 1. 成员 在类中你能写的所有内容都是成员 2 .变量 1) 实例变量: 昨天写的就是实例变量 ,由对象去访问的变量 . cl ... 
- 每天CSS学习之transform
			transform是CSS3的一个属性,其作用是用来进行2D或3D变换. 一.2D变换 1. translate(x-offset , y-offset) translate的作用就是用作位置的移动. ... 
- pymongo 对mongoDB的操作
			#文档地址 http://api.mongodb.com/python/current/api/pymongo/collection.html collection级别的操作: find_and _m ... 
