1. 程式人生 > >LOJ#10002. 「一本通 1.1 例 3」噴水裝置

LOJ#10002. 「一本通 1.1 例 3」噴水裝置

傳統 lock ted sdl pro prim res baseline bottom

#10002. 「一本通 1.1 例 3」噴水裝置

內存限制:512 MiB 時間限制:1000 ms 標準輸入輸出 題目類型:傳統 評測方式:文本比較 上傳者: 1bentong 提交 提交記錄 統計 討論 1 測試數據

題目描述

LLL 米,寬 WWW 米的草坪裏裝有 nnn 個澆灌噴頭。每個噴頭都裝在草坪中心線上(離兩邊各 W2\frac{W}{2}?2??W?? 米)。我們知道每個噴頭的位置(離草坪中心線左端的距離),以及它能覆蓋到的澆灌範圍。

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

技術分享圖片

輸入格式

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

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

每組數據的第一行是整數 nnn、LLL 和 WWW;

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

輸出格式

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

樣例

樣例輸入

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%100\%100% 的數據,n≤15000n \le 15000n15000

細節決定成敗

 1 //2018-07-27 22:23:33
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cmath>
 6 #include <cstring>
 7 using std::sort;
 8 
 9 typedef long
long ll; 10 const int N = 15000001; 11 long long T; 12 long long L, W, n; 13 struct node{ 14 double st, ed; 15 }a[N]; 16 bool cmp(node a, node b){ 17 return a.st < b.st; 18 } 19 20 inline long long read () { 21 ll val = 0, flag = 1; 22 char ch = getchar(); 23 while(ch != - && (ch < 0 || ch > 9)) ch = getchar(); 24 while(ch == -) flag = -flag, ch = getchar(); 25 while(ch >= 0 && ch <= 9) 26 val = ((val << 1) + (val << 3) + ch - 0), ch = getchar(); 27 return val * flag; 28 } 29 30 int main(){ 31 T = read(); 32 while(T--){ 33 // 34 long long cnt = 0; 35 n = read(); L = read(); W = read(); 36 for(long long i=1, pos, r; i<=n; i++){ 37 pos = read(); r = read(); 38 if(r <= W/2) continue; //sfjlsfdsdlfjds 39 a[++cnt].st = pos - sqrt(r*r - W*W/4.0); 40 a[cnt].ed = pos + sqrt(r*r - W*W/4.0); 41 } 42 sort(a+1, a+cnt+1, cmp); 43 // 44 double s = 0; 45 long long i = 1, ans = 0; 46 bool mark = true; 47 while(s < L){ 48 ++ans; 49 double tmp = s; 50 for(;a[i].st<=tmp && i<=cnt; ++i) 51 if(s < a[i].ed) s = a[i].ed; 52 if(s==tmp && tmp < L){ 53 puts("-1"); 54 mark = false; 55 break; 56 } 57 58 } 59 if(mark) printf("%lld\n", ans); 60 61 62 } 63 return 0; 64 }

LOJ#10002. 「一本通 1.1 例 3」噴水裝置