当前位置:网站首页>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;
}边栏推荐
- 初入Redis
- Openwrt source code generation image
- 【练习-6】(PTA)分而治之
- 栈的经典应用—括号匹配问题
- Information security - Analysis of security orchestration automation and response (soar) technology
- Penetration test (8) -- official document of burp Suite Pro
- Interval sum ----- discretization
- Flink 使用之 CEP
- If you want to apply for a programmer, your resume should be written like this [essence summary]
- E. Breaking the Wall
猜你喜欢

2027. Minimum number of operations to convert strings

“鬼鬼祟祟的”新小行星将在本周安全掠过地球:如何观看

Information security - threat detection engine - common rule engine base performance comparison
![[exercise-5] (UVA 839) not so mobile (balance)](/img/8e/48dcf75f7347b36301df6fc129c09d.png)
[exercise-5] (UVA 839) not so mobile (balance)

渗透测试 ( 3 ) --- Metasploit Framework ( MSF )

Determine the Photo Position

1529. Minimum number of suffix flips

Information security - Analysis of security orchestration automation and response (soar) technology
![MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’](/img/e6/f4a696179282fe1f4193410c5a493a.png)
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’

b站 实时弹幕和历史弹幕 Protobuf 格式解析
随机推荐
b站 實時彈幕和曆史彈幕 Protobuf 格式解析
双向链表—全部操作
Openwrt build Hello ipk
信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
The most complete programming language online API document
Interval sum ----- discretization
Alice and Bob (2021 Niuke summer multi school training camp 1)
Find 3-friendly Integers
Essai de pénétration (1) - - outils nécessaires, navigation
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
If you want to apply for a programmer, your resume should be written like this [essence summary]
Penetration test (8) -- official document of burp Suite Pro
Opencv learning log 26 -- detect circular holes and mark them
对iptables进行常规操作
Information security - threat detection engine - common rule engine base performance comparison
Information security - threat detection - detailed design of NAT log access threat detection platform
[exercise-5] (UVA 839) not so mobile (balance)
Raspberry pie csi/usb camera uses mjpg to realize web camera monitoring
【练习-3】(Uva 442)Matrix Chain Multiplication(矩阵链乘)