1424:噴水裝置

【題目描述】

長 LL 米,寬 WW 米的草坪裏裝有 nn 個澆灌噴頭。每個噴頭都裝在草坪中心線上(離兩邊各 W2W2 米)。我們知道每個噴頭的位置(離草坪中心線左端的距離),以及它能覆蓋到的澆灌範圍。

請問:如果要同時澆灌整塊草坪,最少需要打開多少個噴頭?

【輸入】

輸入包含若干組測試數據。

第一行一個整數 TT 表示數據組數;

每組數據的第一行是整數 nn、LL 和 WW;

接下來的 nn 行,每行包含兩個整數,給出一個噴頭的位置和澆灌半徑(上面的示意圖是樣例輸入第一組數據所描述的情況)。

【輸出】

對每組測試數據輸出一個數字,表示要澆灌整塊草坪所需噴頭數目的最小值。如果所有噴頭都打開也不能澆灌整塊草坪,則輸出 −1−1 。

【輸入樣例】

3
8 20 2
5 3
4 1
1 2
7 2
10 2
13 3
16 2
19 4
3 10 1
3 5
9 3
6 1
3 10 1
5 3
1 1
9 1

【輸出樣例】

6
2
-1

【提示】

數據範圍:

對於 100% 的數據,n≤15000。

 

//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define rush() int T;cin>>T;while(T--)
#define go(a) while(cin>>a)
#define ms(a,b) memset(a,b,sizeof a)
#define E 1e-8
#define debug(a) cout<<"*"<<a<<"*"<<endl
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define s first
//#define e second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<double,double> Pair;
const int inf=0x3f3f3f3f;
const int N=3e4+5;

    int n,m,t;
    int i,j,k;
    Pair p[N];
bool cmp(Pair a,Pair b)
{
    return a.first<b.first;
}
int main()
{
    IOS;
    rush(){
        double L,w;
        cin>>n>>L>>w; w/=2.0;
        int num=0,r,pos;
        for(i=0;i<n;i++){
            cin>>pos>>r;
            if(r<=w) continue;
            double dis=sqrt(r*r-w*w);
            num++;
            p[num].first=pos-dis; p[num].second=pos+dis;
        }
        sort(p+1,p+num+1,cmp);


        double ddl=0;
        int cur=1,ans=0,flag=1;
        while(ddl<L&&flag){
            if(ddl<p[cur].first&&cur<=num){ flag=0; break;}
            ans++; double tmp=ddl;
            while(p[cur].first<=tmp&&cur<=num){
                if(p[cur].second>ddl) ddl=p[cur].second;
                cur++;
            }
            //cout<<ddl<<endl;
        }
        if(flag) cout<<ans<<endl;
        else cout<<-1<<endl;
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章