nyoj 6 喷水装置(一) (贪心)


<div class="problem-display" style="font-size: 14px; color: rgb(70, 70, 70); font-family: Tahoma, Arial, sans-serif, simsun;"><h2 style="margin: 0px; padding: 0px; font-size: 18px; text-align: center; color: rgb(113, 32, 21); font-family: 微软雅黑, 黑体;">喷水装置(一)</h2><div class="problem-ins" style="text-align: center;">时间限制:<span class="editable highlight" id="problem[time_limit]" style="color: rgb(113, 32, 21);">3000</span> ms  |  内存限制:<span class="editable highlight" id="problem[memory_limit]" style="color: rgb(113, 32, 21);">65535</span> KB</div><div class="problem-ins" style="text-align: center;">难度:<span class="editable highlight" style="color: rgb(113, 32, 21);">3</span></div></div><div class="clr" style="clear: both; color: rgb(70, 70, 70); font-family: Tahoma, Arial, sans-serif, simsun; font-size: 13px; line-height: 19.5px;"></div><dl class="problem-display" style="margin: 0px; padding: 0px; font-size: 14px; color: rgb(70, 70, 70); font-family: Tahoma, Arial, sans-serif, simsun;"><dt style="margin: 1em 0px 0.2em; padding: 0px; color: rgb(113, 32, 21); font-size: 16px; font-weight: bold;">描述</dt><dd style="margin: 0px; padding: 0px;">现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中心的半径为实数Ri(0<Ri<15)的圆被湿润,这有充足的喷水装置i(1<i<600)个,并且一定能把草坪全部湿润,你要做的是:选择尽量少的喷水装置,把整个草坪的全部湿润。</dd><div class="clr" style="clear: both;"></div><dl class="others" style="margin: 0px; padding: 0px;"><dt style="margin: 1em 0px 0.2em; padding: 0px; color: rgb(113, 32, 21); font-size: 16px; font-weight: bold;">输入</dt><dd style="margin: 0px; padding: 0px;">第一行m表示有m组测试数据
每一组测试数据的第一行有一个整数数n,n表示共有n个喷水装置,随后的一行,有n个实数ri,ri表示该喷水装置能覆盖的圆的半径。</dd><dt style="margin: 1em 0px 0.2em; padding: 0px; color: rgb(113, 32, 21); font-size: 16px; font-weight: bold;">输出</dt><dd style="margin: 0px; padding: 0px;">输出所用装置的个数</dd><dt style="margin: 1em 0px 0.2em; padding: 0px; color: rgb(113, 32, 21); font-size: 16px; font-weight: bold;">样例输入</dt><dd style="margin: 0px; padding: 0px;"><pre id="sample_input" style="margin-top: 0px; margin-bottom: 0px; padding: 5px 10px; font-family: Consolas, 'Courier New', 'DejaVu Sans Mono', 'Droid Sans Mono', monospace; border: 1px solid rgb(204, 204, 204); min-height: 20px; line-height: 1.5em; background: rgb(239, 239, 239);">2
5
2 3.2 4 4.5 6 
10
1 2 3 1 2 1.2 3 1.1 1 2
样例输出
2
5

 
 
注意double和int型,s,cmp,a[1000]都是浮点型,整型结果错误!

代码:

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

bool cmp(double a,double b)
{
    return a>b ;
}
int main()
{
    int t,n;
    double a[1000],s;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%lf",&a[i]);
        }
        sort(a,a+n,cmp);
        int k=0;
        s=0;
        for(int i=0;i<n,s<20;i++)
        {
            s+=2.0*sqrt(a[i]*a[i]-1);
            k++;
           /* if(s>=20)
            {
                break;
            }*/
        }
        printf("%d\n",k);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值