Stripies

时间限制: 1000 ms | 内存限制: 65535 KB
难度: 1
描述
Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, but the scientists had to invent an English name to apply for an international patent). The stripies are transparent amorphous amebiform creatures that live in flat colonies in a jelly-like nutrient medium. Most of the time the stripies are moving. When two of them collide a new stripie appears instead of them. Long observations made by our scientists enabled them to establish that the weight of the new stripie isn't equal to the sum of weights of two disappeared stripies that collided; nevertheless, they soon learned that when two stripies of weights m1 and m2 collide the weight of resulting stripie equals to 2*sqrt(m1*m2). Our chemical biologists are very anxious to know to what limits can decrease the total weight of a given colony of stripies.
You are to write a program that will help them to answer this question. You may assume that 3 or more stipies never collide together.
输入
The first line of the input contains one integer N (1 <= N <= 100) - the number of stripies in a colony. Each of next N lines contains one integer ranging from 1 to 10000 - the weight of the corresponding stripie.
输出
The output must contain one line with the minimal possible total weight of colony with the accuracy of three decimal digits after the point.
样例输入
3
72
30
50
样例输出
120.000

题意: 题目就是说有n个物品,每个物品重w[i],对于两个物品他们合并时重量就会变成

w = 2 * sqrt(w[a] * w[b])。 问当n个物品合成一个时,最小重量是多少?

题解:要用到一点数学知识,在n个物品中取两个物品合并,要想最后总重最小,要每次取两个重量最大的物品。关于这个结论,下面给出证明:

设:n=3,三个物品的重量分比为:a,b,c, 合并之后最小重量为w。

则w = 2 * sqrt( a* 2 * sqrt(b * c) )

化简后的 w^2/8 = sqrt( a*a*b*c ), 此式可得 a 取最小时 w 的值最小。

归纳总结,n个物品每次取最大的两个合并,总重最小。

#include<iostream>  
#include<cstring>  
#include<algorithm>  
#include<cmath>  
#include<iomanip>
using namespace std;  
bool cmp(int a,int b)
{
    return a>b;
}
double w[110];  
int n;  
int main()  
{  
    int i,j,k;  
    while(cin>>n)  
    {  
        for(i=0;i<n;i++)  
           cin>>w[i];  
        sort(w,w+n,cmp);  
        for(i=0;i<n;i++)  
           w[i+1] =2*sqrt(w[i]*w[i+1]);
        cout<<setprecision(3)<<std::fixed<<w[n-1]<<endl;   
    }  
    return 0;
}  

NYOJ 354 问当n个物品合成一个时,最小重量是多少?相关推荐

  1. rpgmakermv(6) YEP_ItemSynthesis.js物品合成插件

    物品合成插件. 用途?太多了呢. 低级宝石合成高级,还有装备,武器,药水等等. ============================================================ ...

  2. [游戏数据表]泰拉瑞亚Terraria 全物品合成表

    <泰拉瑞亚>中文合成表 适用于 Terraria v1.3.5.2 官方中文版    2017-5-15 by SJF 中英文部分均提取自 Terraria. exe. 从exe导出的文本 ...

  3. [游戏数据表]七日杀 7DAYS TO DIE全物品合成表

    七日杀 7DAYS TO DIE全物品合成表 相关资料: 1. 七日杀 v6合成表查询工具 2.

  4. Minecraft Fabric模组开发 (四) 添加物品合成表

    添加物品合成表 添加基础的合成(其实跟原版合成一样) 新建目录resources/data/tutorial/recipes 在目录下新建名为物品ID的json文件(以羊毛斧为例),添加如下代码 {& ...

  5. 如何将1000页PPT单独导出为1000个单独的文件?又如何快速把多个PPT合成一个?

    如何将1000页PPT单独导出为1000个单独的文件?又如何快速把多个PPT合成一个? 来了,来了,最近有粉丝留言,问了2个问题,觉得很有意思,也很好玩. 问题1:能不能把多个PPT合并成一个? 比如 ...

  6. R语言使用car包的influencePlot函数将回归分析中的离群点(outlier)、杠杆(leverage)和影响(influence)的信息组合成一个高度信息量丰富的合成图

    R语言使用car包的influencePlot函数将回归分析中的离群点(outlier).杠杆(leverage)和影响(influence)的信息组合成一个高度信息量丰富的合成图 目录

  7. python ffmpeg 视频转图片 视频转音频 播放音频 多张图片+音频转视频 多个视频合成一个视频 改变视频播放速度

    文章目录 视频转图片 视频转音频 播放音频 图片+音频 转 视频 多个视频合成一个视频 改变视频播放速度 视频转图片 #!/usr/bin/env python # -*- encoding: utf ...

  8. python怎么输出一个数组_python中实现将多个print输出合成一个数组

    比如有下面一段代码: for i in range(10): print ("%s" % (f_list[i].name)) 该代码段的执行,会生成如下的10行"name ...

  9. 用SSAS将多个FLV和MP3合成一个FLV文件

    用SSAS合成FLV 使用SSAS把两个或多个FLV文件合成一个FLV,可以控制FLV的长度,SSAS写法如下: =========================================== ...

最新文章

  1. SQL取出每个产品的Top n 条记录
  2. echarts python源码_基于Django快速集成Echarts代码示例
  3. Strings.Replace 方法的注意事项
  4. mysql 无论输入什么都是现实 not found_NotAPanda
  5. 分布式查询处理和优化相关知识介绍
  6. Tomcat配置解析
  7. python字典_python字典可变吗
  8. nodejs和cnpm安装
  9. 机器学习基础-朴素贝叶斯分类
  10. background-color:#e5eecc; border:solid 1px #c3c3c3;
  11. Anylogic学习--------------三维窗口
  12. ev加密视频转换成MP4格式,亲测可用
  13. 物联网嵌入式——学习分享
  14. Spring中Environment的使用
  15. 华为云AI随笔(2)
  16. 学习笔记 C++ 动态数组类的声明
  17. 用数组来实现一个循环队列
  18. 工装,夹具,治具,检具
  19. 一个可以截取其他App素材的办法Visual Studio Code
  20. 陀螺仪与磁力计的姿态融合——互补滤波(续)

热门文章

  1. MapReduce 编程实践
  2. dh命令(ssh命令详解)
  3. 前端小白面试指南-李游Leo-专题视频课程
  4. 【2.3.3被拒】苹果iOS上架没有真机提供ps制作屏幕截图
  5. 007 量化交易资源总结
  6. python实现模拟器的重启
  7. 移动端界面适配 —— 多方案解析
  8. 共享代购项目计划书_20180704
  9. keepalived配置日志与防火墙
  10. Python奇异值分解