当前位置:网站首页>Radar equipment (greedy)
Radar equipment (greedy)
2022-07-06 16:08:00 【AC__ dream】

analysis : First, give the location of an island , We can find out the position range where this radar can be placed , It means that as long as the radar is placed in this section , Then the island can be covered by radar , Altogether n An island , Then the corresponding can also be found n Intervals , At this time, there should be at least one radar in each section , But there may be coincidence between intervals Of , In other words, we require a minimum number of radars so that there is at least one radar in each interval , Then this is obviously a greedy problem , Let's sort all the intervals according to the right endpoint , Then we record a r Represents the location of the last radar , If the current range is r To the right of , Then we should at least install another radar , Because there is no longer an island on the left side of the current range that is not covered , So our radar is placed on the right as far as possible , But also within the current range , So it is placed on the right end of the current interval , Place in sequence , Add the number of radars every time you place one 1, Finally, output the number of radars .
Here is the code :
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
const int N=1003;
int n,d;
struct node{
double l,r;
}p[N];
bool cmp(node a,node b)
{
return a.r<b.r;
}
void f(int i,int x,int y)
{
p[i]={x-sqrt(1.0*d*d-y*y),x+sqrt(1.0*d*d-y*y)};
}
int main()
{
cin>>n>>d;
int x,y;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(y>d)
{
puts("-1");
return 0;
}
f(i,x,y);
}
sort(p+1,p+n+1,cmp);
double r=-9999;
int cnt=0;
for(int i=1;i<=n;i++)
{
if(p[i].l>r)
{
r=p[i].r;
cnt++;
}
}
printf("%d",cnt);
return 0;
}边栏推荐
- nodejs爬虫
- JS调用摄像头
- Nodejs crawler
- Truck History
- Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
- 渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
- Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
- Penetration test (1) -- necessary tools, navigation
- JS call camera
- New to redis
猜你喜欢

1689. Ten - the minimum number of binary numbers

B - Code Party (girls' competition)

605. Planting flowers
![[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class](/img/57/bc6eda91f7263acda38b9ee8732318.png)
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
![[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class](/img/3b/dc43564a36f82e73826b08f39c935e.png)
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class

Penetration test (7) -- vulnerability scanning tool Nessus

Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B

【高老师UML软件建模基础】20级云班课习题答案合集

信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志

Programmers, what are your skills in code writing?
随机推荐
双向链表—全部操作
Auto. Getting started with JS
b站 实时弹幕和历史弹幕 Protobuf 格式解析
Quick to typescript Guide
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
【练习-1】(Uva 673) Parentheses Balance/平衡的括号 (栈stack)
X-Forwarded-For详解、如何获取到客户端IP
B - Code Party (girls' competition)
对iptables进行常规操作
【高老师软件需求分析】20级云班课习题答案合集
TCP's three handshakes and four waves
Ball Dropping
Opencv learning log 27 -- chip positioning
Pyside6 signal, slot
Opencv learning log 19 skin grinding
1529. Minimum number of suffix flips
Penetration test (3) -- Metasploit framework (MSF)
C language learning notes
JS call camera
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)