【贪心】时空定位II
【贪心】时空定位II
题目描述
输入
每一组测试数据的第一行有三个整数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
分析:将雷达覆盖的边界起点从小到大排序,对起点小于等于当前起点的雷达,选取最大的终点即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,cnt,flag,w,h,all;
pair<double,double>a[maxn];
double x,y,now;
int main()
{
int i,j,k,t;
scanf("%d",&t);
while(t--)
{
flag=true;
all=cnt=;
scanf("%d%d%d",&n,&w,&h);
rep(i,,n-){
scanf("%lf%lf",&x,&y);
if(y>1.0*h/)
a[all].fi=x-sqrt(y*y-h*h/),a[all++].se=x+sqrt(y*y-h*h/);
}
sort(a,a+all);
now=;
//rep(i,0,all-1)cout<<a[i].fi<<" "<<a[i].se<<endl;
for(i=;i<all;i++)
{
if(now>=w)break;
double ma=-;
while(i<all&&a[i].fi<=now)ma=max(ma,a[i].se),i++;
if(ma!=-)flag=true,now=ma,cnt++,i--;
else
{
flag=false;break;
}
}
if(flag&&now>=w)printf("%d\n",cnt);
else puts("");
}
//system ("pause");
return ;
}
【贪心】时空定位II的更多相关文章
- 【贪心】时空定位I
[贪心]时空定位I 题目描述 张 琪曼已经确定了李旭琳在一个长为20千米,宽为2千米的空间,她要在横中心线上放置半径为Ri的定位装置,每个定位装置的效果都会让以它为中心的半径为实 数Ri(0<R ...
- ### Paper about Event Detection
Paper about Event Detection. #@author: gr #@date: 2014-03-15 #@email: forgerui@gmail.com 看一些相关的论文. 1 ...
- Noip2019暑期训练1
题目名称 时空定位 棋子移动 高精度乘法 数独游戏 存盘文件名 location piece mul sudoku 输入文件名 location.in piece.in mul.in sudoku.i ...
- python与正则表达式
匹配一个字符: . 任意非\n字符 [...] \d \D digit \s \S space \w \W word 匹配前一个字符的多个: * 0->> + 1->> ? 0 ...
- ###《High-level event recognition in unconstrained videos》
Author: Yu-Gang Jiang, Shih-Fu Chang 事件检测的目标就是自动识别给定视频序列中的感兴趣事件.进行视频事件检测通常很困难,特别是在网络中非限制的视频.在非限制情况下, ...
- 超计算(Hyper computation)模型
超计算(Hyper computation)模型 作者:Xyan Xcllet链接:https://www.zhihu.com/question/21579465/answer/106995708来源 ...
- LEETCODE —— Best Time to Buy and Sell Stock II [贪心算法]
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...
- Algorithm - 贪心算法使用场景 ( LEETCODE —— Best Time to Buy and Sell Stock II)
先看一道leetcode题: Best Time to Buy and Sell Stock II Say you have an array for which the ith element is ...
- Jump Game I&&II——入门级贪心算法
Jump Game I Given an array of non-negative integers, you are initially positioned at the first index ...
随机推荐
- OA系统出现窗口拦截的解决办法
我们使用oa时候,有时候会出现“你打开了窗口拦截功能”.如图 出现窗口被拦截主要有三种情况,分别是IE浏览器本身拦截功能.第三方插件(如百度工具栏.搜搜工具栏.谷歌工具栏等).第三方浏览器拦截功能(如 ...
- git远程分支--remote
查看所有远程引用: $ git ls-remote From ssh://someone@example/testgit ebf3ef7551603cd57a699e80db0bfab36d1aa7b ...
- List-----Array
1.Definition Arry数组是一种连续储存的List 储存方式:将线性表中的元素一次储存在连续的储存空间中. Computer's logical structure: 逻辑位置上相邻的元素 ...
- 7.在第4题中Hello.class所在路径下, 输入命令:java Hello.class,会出现什么结果,为什么?
java Hello已经是加载类了
- string 转 int,int 转 string
string str="12345"; int b=atoi(str.c_str()); 可以配合atof,转为double char buf[10]; sprintf(buf, ...
- frameset框架样式 加边框
<frameset rows="580,*" FRAMESPACING="3"> <frame noresize name="Top ...
- [转载] 关于Windows Boot Manager、Bootmgfw.efi、Bootx64.efi、bcdboot.exe 的详解
原帖: http://bbs.wuyou.net/forum.php?mod=viewthread&tid=303679 前言:1.本教程针对于UEFI启动来叙述的,根据普遍的支持UEFI的机 ...
- IOS抓包工具paros的使用
一,环境安装,软件安装 1.下载安装java JDK for Mac,可以从Oracle官网下载(但是一般Oracle的都是最新的版本的),或者从苹果的开发者网站下载,我是从苹果官网下载的javafo ...
- Servlet学习三:不允许直接访问jsp处理方式一过滤器
转自:http://zy19982004.iteye.com/blog/1755189
- WPF之TabControl控件用法
先创建实体基类:NotificationObject(用来被实体类继承) 实现属性更改通知接口: using System; using System.Collections.Generic; usi ...