【贪心】时空定位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 ...
随机推荐
- HDU 3499 Flight spfa+dp
Flight Time Limit : 20000/10000ms (Java/Other) Memory Limit : 65535/65535K (Java/Other) Total Subm ...
- VS中的快捷键快速格式化代码,使好看,整齐
在VC2005中,快捷键是Ctrl + K, Ctrl + F, 这是一个组合键,即先按Ctrl + K, 这时候编辑器会等待下一个按键动作,此时再按Ctrl + F, 即可以格式化代码了,当然,也可 ...
- <context:annotation-config> 和 <context:component-scan>的区别
转自:GOOD spring <context:annotation-config> 跟 <context:component-scan>诠释及区别 <context:a ...
- Entity Framework技巧系列之十二 - Tip 46 - 50
提示46. 怎样使用Code-Only排除一个属性 这次是一个真正简单的问题,由StackOverflow上这个问题引出. 问题: 当我们使用Code-Only把一个类的信息告诉Entity F ...
- LeetCode OJ 96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- crontab如何设置秒级别的定时【转载】
* * * * * date > /home/gamester88/test/nihao.txt * * * * * (sleep 10 && date >> /ho ...
- Linux 配置脚本 启动服务
之前在mac安装了php和nginx每次都用一堆命令重启 今天没事情干,心血来潮,自己研究写了一段shell脚本来重启 首先vim /usr/sbin/pn 代码如下 #! /bin/bash php ...
- 获取输入设备的vid和pid
一.获取/dev/input/event16设备的vid和pid testhid.c #include <linux/types.h> #include <linux/input.h ...
- nuget pack 时不包含依赖包(而不是引用项目的dll,区别于IncludeReferencedProjects)
Excluding development dependencies when creating packages Some NuGet packages are useful as developm ...
- git clean -fdx
http://stackoverflow.com/questions/5807137/git-how-to-revert-uncommitted-changes-including-files-and ...