当前位置:网站首页>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;
}
边栏推荐
- [exercise 4-1] cake distribution
- Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
- mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
- The concept of C language array
- [exercise-8] (UVA 246) 10-20-30== simulation
- Basic Q & A of introductory C language
- Ball Dropping
- Truck History
- Information security - threat detection engine - common rule engine base performance comparison
- Borg maze (bfs+ minimum spanning tree) (problem solving report)
猜你喜欢
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
滲透測試 ( 1 ) --- 必備 工具、導航
Penetration test (3) -- Metasploit framework (MSF)
C language is the watershed between low-level and high-level
快速转 TypeScript 指南
【高老师UML软件建模基础】20级云班课习题答案合集
B - Code Party (girls' competition)
B - 代码派对(女生赛)
b站 实时弹幕和历史弹幕 Protobuf 格式解析
D - function (HDU - 6546) girls' competition
随机推荐
HDU - 6024 building shops (girls' competition)
Openwrt source code generation image
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
1529. Minimum number of suffix flips
[exercise-5] (UVA 839) not so mobile (balance)
Opencv learning log 27 -- chip positioning
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
1689. Ten - the minimum number of binary numbers
Information security - threat detection - detailed design of NAT log access threat detection platform
Opencv learning log 18 Canny operator
Opencv learning log 13 corrosion, expansion, opening and closing operations
7-1 understand everything (20 points)
frida hook so层、protobuf 数据解析
Alice and Bob (2021 Niuke summer multi school training camp 1)
If you want to apply for a programmer, your resume should be written like this [essence summary]
b站 實時彈幕和曆史彈幕 Protobuf 格式解析
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
Analysis of protobuf format of real-time barrage and historical barrage at station B
Opencv learning log 29 -- gamma correction
nodejs爬虫