码迷,mamicode.com
首页 > 其他好文 > 详细

【贪心】时空定位I

时间:2018-07-21 00:10:06      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:stream   def   out   size   one   clu   col   style   opened   

题目描述

张琪曼已经确定了李旭琳在一个长为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 <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int t,n;
double aa[1005];
void init(){
    cin>>t;
}
void solve(){
    while(t--){
        cin>>n;
        range(i,0,n-1)cin>>aa[i];
        sort(aa,aa+n);
        int cnt=0;double now=0;
        rerange(i,n-1,0){
            if(now>=20)break;
            now+=2*sqrt(aa[i]*aa[i]-1);
            ++cnt;
        }
        cout<<cnt<<endl;
    }
}
int main() {
    init();
    solve();
    return 0;
}
View Code

 

【贪心】时空定位I

标签:stream   def   out   size   one   clu   col   style   opened   

原文地址:https://www.cnblogs.com/Rhythm-/p/9344632.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!