【贪心】时空定位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 ...
随机推荐
- shape的使用
android在布局边缘位置处理圆角的两个办法: 1),一个是直接让美工切一张带有圆角的图片. 2),使用shape来解决. 第一种不在赘述,主要讲一下第二中方法来实现. 上边缘出现圆角,下边缘正常的 ...
- $.getjson方法配合在url上传递jsoncallback=?参数,实现跨域获取指定网站某商品访问量
across.php文件在域名www.cms.com程序中 <html><body><div id="pv">99</div>< ...
- ios中的关键词@property @synthesize
@interface Person : NSObject{ int myNumber;} @property(nonatomic) int myNumber;//这个关键字是可以带套get 与s ...
- SQL SERVER与C#的数据类型对应表
序号 类别 SQLServer C Sharp 备注 1 整数 bit Boolean True转换为1False转换为0 2 tinyint Byte C Sharp 数据类型都位于System命名 ...
- PHP数学函数试题
1.求绝对值的函数是什么? 2.在任意进制之间转换数字的函数是什么? 3.二进制转换为十进制,十进制转换为二进制,十六进制转换为十进制,十进制转换为十六进制,八进制转换为十进制,十进制转换为八进制的函 ...
- Inno Setup入门(十九)——Inno Setup类参考(5)
: Install Setup 2013-02-02 11:29 377人阅读 评论(0) 收藏 举报 单选按钮 单选按钮在安装中也很常见,例如同一个程序可以选择安装不同的性质的功能,例如选择32位或 ...
- wl18xx编译的时候出现WARNING: "simple_open" WARNING: "wl12xx_get_platform_data"
................................................................................................... ...
- J2EE判断重复的数据
import java.util.ArrayList; import java.util.List; import org.junit.Test; /** * 判断重复的数据 * @author Ya ...
- 【floyd 多源最短路】 poj 1125
#include <stdio.h> #include <iostream> #include <memory.h> using namespace std; ][ ...
- 【贪心】 poj 1032 和为n的若干数最大乘积
给出n,把n分解为若干不相同数之和,使之乘积最大.贪心,Discuss里面的思路:把n分解为从2开始的连续整数,如果有多,则从高位开始依次加1.如26,我们得到2+3+4+5+6,此时还剩余6(26- ...