3 solutions

  • 0
    @ 2026-4-19 13:48:16

    • 0
      @ 2026-4-19 13:42:19

      • 0
        @ 2025-7-2 10:29:54
        #include<bits/stdc++.h>
        using namespace std;
        typedef pair<double,double> PDD;
        #define l first
        #define r second
        const int N=1010;
        PDD range[N]; 
        bool cmp(PDD a,PDD b)
        {
            return a.r<b.r;
        }
        int main()
        {
        	int n,d;
        	cin>>n>>d;
        	for(int i=0;i<n;i++)
        	{
        		int x,y;
        		cin>>x>>y;
        		if(y>d)
        		{
        			cout<<"-1"<<endl;
        			return 0;
        		}
        		double len=sqrt(d*d-y*y);
        		range[i]={x-len,x+len}; //得到可以覆盖当前小岛的雷达可安装范围
        	}
        	sort(range,range+n,cmp); //从小到大排序
        	int res=0;
        	double ed=-2e9; 
        	for(int i=0;i<n;i++)
        	{
        		if(range[i].l>=ed)
        		{
        		    res++;
        		    ed=range[i].r;
        		}
        	}
        	cout<<res;
        	return 0;
        }
        
        • 1

        Information

        ID
        248
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        5
        Tags
        # Submissions
        23
        Accepted
        11
        Uploaded By