• 【贪心】时空定位I


    【贪心】时空定位I

    题目描述

    张 琪曼已经确定了李旭琳在一个长为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 <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #include <ext/rope>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define vi vector<int>
    #define pii pair<int,int>
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    const int maxn=1e3+10;
    const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
    using namespace std;
    using namespace __gnu_cxx;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    int n,m,cnt;
    double a[maxn],now;
    int main()
    {
        int i,j,k,t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            rep(i,0,n-1)scanf("%lf",&a[i]);
            sort(a,a+n);
            cnt=0;now=0;
            for(i=n-1;i>=0;i--)
            {
                if(now>=20)break;
                now+=2*sqrt(a[i]*a[i]-1);
                cnt++;
            }
            printf("%d
    ",cnt);
        }
        //system ("pause");
        return 0;
    }
  • 相关阅读:
    windows AD监听的端口
    [FreeBSD] 双网卡绑定
    Kea DHCP MySQL
    NTP服务器知识整理
    linux的常用命令
    配置squid集成域身份认证
    Windows上配置PHP的LDAP扩展
    PHP下使用ldap域账户认证密码
    理解syslinux,SYSLINUX和PXELINUX
    优化pxe网启动时tftp的传输速度 --- 针对pxelinux和bootmgr
  • 原文地址:https://www.cnblogs.com/dyzll/p/5697007.html
Copyright © 2020-2023  润新知