当前位置:网站首页>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;
}
边栏推荐
- Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
- Shell脚本编程
- 想应聘程序员,您的简历就该这样写【精华总结】
- Opencv learning log 28 -- detect the red cup cover
- Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
- SSM框架常用配置文件
- 【练习4-1】Cake Distribution(分配蛋糕)
- 渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
- 栈的经典应用—括号匹配问题
- 信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
猜你喜欢
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
Information security - Analysis of security orchestration automation and response (soar) technology
X-forwarded-for details, how to get the client IP
信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
D - function (HDU - 6546) girls' competition
7-1 懂的都懂 (20 分)
信息安全-威胁检测引擎-常见规则引擎底座性能比较
Gartner:关于零信任网络访问最佳实践的五个建议
C language must memorize code Encyclopedia
Openwrt build Hello ipk
随机推荐
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
Opencv learning log 15 count the number of solder joints and output
Perform general operations on iptables
栈的经典应用—括号匹配问题
想应聘程序员,您的简历就该这样写【精华总结】
1005. Maximized array sum after K negations
【练习-6】(Uva 725)Division(除法)== 暴力
China exterior wall cladding (EWC) market trend report, technical dynamic innovation and market forecast
[exercise -11] 4 values why sum is 0 (and 4 values of 0)
[exercise-2] (UVA 712) s-trees
CEP used by Flink
C language must memorize code Encyclopedia
1689. Ten - the minimum number of binary numbers
Hdu-6025-prime sequence (girls' competition)
Penetration test (4) -- detailed explanation of meterpreter command
【练习-10】 Unread Messages(未读消息)
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
Borg Maze (BFS+最小生成树)(解题报告)
Auto.js入门
JS调用摄像头