噴水裝置(一)
時間限制:3000 ms | 內存限制:65535 KB
難度:3
-
描述
- 現有一塊草坪,長爲20米,寬爲2米,要在橫中心線上放置半徑爲Ri的噴水裝置,每個噴水裝置的效果都會讓以它爲中心的半徑爲實數Ri(0<Ri<15)的圓被溼潤,這有充足的噴水裝置i(1<i<600)個,並且一定能把草坪全部溼潤,你要做的是:選擇儘量少的噴水裝置,把整個草坪的全部溼潤。
-
輸入
- 第一行m表示有m組測試數據
每一組測試數據的第一行有一個整數數n,n表示共有n個噴水裝置,隨後的一行,有n個實數ri,ri表示該噴水裝置能覆蓋的圓的半徑。 -
輸出
- 輸出所用裝置的個數
-
樣例輸入
-
2
5
2 3.2 4 4.5 6
10
1 2 3 1 2 1.2 3 1.1 1 2
-
樣例輸出
-
2
5
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int n;
cin>>n;
while(n){
int m;
cin>>m;
vector<double> s1;
double k=0.0;
while(m){
cin>>k;
s1.push_back(k);
m--;
}
sort(s1.begin(),s1.end());
double kk=0.0;
int j=0;
for(int i=s1.size()-1;i>=0;i--){
while(kk<20.1 && i>=0){
kk+=s1[i--]*2;j++;
}
break;
}
if(kk>=20.1)
cout<<j<<endl;
n--;
}
return 0;
}
噴水裝置(二)
時間限制:3000 ms | 內存限制:65535 KB
難度:4
-
描述
- 有一塊草坪,橫向長w,縱向長爲h,在它的橫向中心線上不同位置處裝有n(n<=10000)個點狀的噴水裝置,每個噴水裝置i噴水的效果是讓以它爲中心半徑爲Ri的圓都被潤溼。請在給出的噴水裝置中選擇儘量少的噴水裝置,把整個草坪全部潤溼。
-
輸入
- 第一行輸入一個正整數N表示共有n次測試數據。
每一組測試數據的第一行有三個整數n,w,h,n表示共有n個噴水裝置,w表示草坪的橫向長度,h表示草坪的縱向長度。
隨後的n行,都有兩個整數xi和ri,xi表示第i個噴水裝置的的橫座標(最左邊爲0),ri表示該噴水裝置能覆蓋的圓的半徑。 -
輸出
- 每組測試數據輸出一個正整數,表示共需要多少個噴水裝置,每個輸出單獨佔一行。
如果不存在一種能夠把整個草坪溼潤的方案,請輸出0。 -
樣例輸入
-
2
2 8 6
1 1
4 5
2 10 6
4 5
6 5
-
樣例輸出
-
1
2
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
using namespace std;
struct point{
int x;
double r;
double lx;
double rx;
};
bool comp(point xx,point y){
return xx.lx<y.lx;
}
int main()
{
int n;
cin>>n;
while(n){
int m,l,w;
cin>>m>>l>>w;
vector<point> s1;
int k1,k2;
for(int ii=0;ii<m;ii++){
cin>>k1>>k2;
point p1;
p1.x=k1;p1.r=k2;
int kl=sqrt(k2*k2-(w/2)*(w/2));
if(kl>0){p1.lx=k1-kl;
p1.rx=k1*2-p1.lx;
s1.push_back(p1);}
//m--;
}
sort(s1.begin(),s1.end(),comp);
int flg=1,sum=0,count=0;
double max;
while(sum<l){
max=0;
for(int i=0;i<=m-1&&s1[i].lx<=sum;i++){
if(s1[i].rx-sum>max)
max=s1[i].rx-sum;
}
if(max==0)
{flg=0;break;}
else
{sum+=max;count++;}
}
if(flg)
cout<<count<<endl;
else
cout<<"0"<<endl;
n--;
}
return 0;
}