喷水装置(信息学奥赛一本通-T1424)
生活随笔
收集整理的這篇文章主要介紹了
喷水装置(信息学奥赛一本通-T1424)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【題目描述】
長L 米,寬 WW 米的草坪里裝有 n 個澆灌噴頭。每個噴頭都裝在草坪中心線上(離兩邊各 W/2 米)。我們知道每個噴頭的位置(離草坪中心線左端的距離),以及它能覆蓋到的澆灌范圍。
請問:如果要同時澆灌整塊草坪,最少需要打開多少個噴頭?
【輸入】
輸入包含若干組測試數據。
第一行一個整數 T 表示數據組數;
每組數據的第一行是整數 n、L?和 W;
接下來的 n 行,每行包含兩個整數,給出一個噴頭的位置和澆灌半徑(上面的示意圖是樣例輸入第一組數據所描述的情況)。
【輸出】
對每組測試數據輸出一個數字,表示要澆灌整塊草坪所需噴頭數目的最小值。如果所有噴頭都打開也不能澆灌整塊草坪,則輸出 -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
【源程序】
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 100000+5; const int dx[] = {-1,1,0,0,-1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std; struct Node{double pos;double num;bool operator < (const Node &rhs)const{return pos<rhs.pos;} }node[N]; int main(){int t;scanf("%d",&t);while(t--){int n,l,w;scanf("%d%d%d",&n,&l,&w);int cnt=0;for(int i=1;i<=n;i++){int pos,r;scanf("%d%d",&pos,&r);if(r>w/2){node[++cnt].pos=pos-sqrt(r*r-(w/2.0)*(w/2.0));node[cnt].num=pos+sqrt(r*r-(w/2.0)*(w/2.0));}}sort(node+1,node+1+cnt);double len=0;int res=0;bool flag=true;int i=1;while(len<l){res++;double pos=len;while(node[i].pos<=pos&&i<=cnt){if(len<node[i].num)len=node[i].num;i++;}if(len==pos&&pos<l){printf("-1\n");flag=false;break;}}if(flag)printf("%d\n",res);}return 0; }總結
以上是生活随笔為你收集整理的喷水装置(信息学奥赛一本通-T1424)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 种树(信息学奥赛一本通-T1423)
- 下一篇: 【】