STL 训练 POJ - 1862 Stripies
Description
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 2sqrt(m1m2). 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.
Input
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.
Output
The output must contain one line with the minimal possible total weight of colony with the accuracy of three decimal digits after the point.
Sample Input
3
72
30
50
Sample Output
120.000
这个题是一个明显的贪心问题
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=101;
void qrt(const double &x,double &b);
bool cmp(int ax,int bx)
{
return ax>bx;
}
int main()
{
int n;
cin>>n;
double a[maxn];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n,cmp);
for(int i=0;i<n-1;i++)
{
qrt(a[i],a[i+1]);
}
// cout<<a[n-1];
printf("%.3f\n",a[n-1]);
return 0;
}
void qrt(const double &x,double &b)
{
b=2*sqrt(x*b);
}
STL 训练 POJ - 1862 Stripies的更多相关文章
- poj 1862 Stripies/优先队列
原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...
- POJ 1862 Stripies 贪心+优先队列
http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...
- POJ 1862 Stripies (哈夫曼树)
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10263 Accepted: 4971 Descrip ...
- POJ 1862 Stripies【哈夫曼/贪心/优先队列】
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18198 Accepted: 8175 Descrip ...
- POJ 1862 Stripies#贪心(水)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...
- POJ 1862 Stripies
每次合并最大的两个,优先级队列维护一下. 输出的时候%.3lf G++会WA,C++能AC,改成%.3f,都能AC. #include<cstdio> #include<cstrin ...
- POJ 1862 Stripies 【优先队列】
题意:科学家发现一种奇怪的东西,他们有重量weight,如果他们碰在一起,总重变成2*sqrt(m1*m2).要求出最终的重量的最小值. 思路:每次选取质量m最大的两个stripy进行碰撞结合,能够得 ...
- 几道STL题目(FJUT - OJ STL训练1)
这个OJ一直在做,一些专题题目都很好,从易至难,阶梯上升,很适合像我这样的蒟蒻 =7= 这篇是关于其中一个专题训练的题解思路及代码 http://120.78.128.11/Contest.jsp ...
- POJ 1862 & ZOJ 1543 Stripies(贪心 | 优先队列)
题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
随机推荐
- 使用mpvue开发小程序教程
从vue到mpvue再到微信小程序,这么几天下来感觉被搞晕了.三者之间的很多功能存在差异,项目也快接近尾声了,坑也踩了很多了,现在给后来的你们一点总结性经验: 1. 在模板中,动态插入HTML的v-h ...
- jvm入门及理解(一)——简介与体系架构
最近,在学习java虚拟机的内容中,在此总结和记录下学到的. 一.JVM在计算机中的位置 在我们初学java时,便知道java源文件文件会先通过Java编译器编译成字节码文件,这个过程是java编译过 ...
- 7.2 java 类的定义和使用
/* * 类的定义: * 类是用来描述现实世界的事物的 * * 事物: * 属性 事物的描述信息 * 行为 事物能够做什么 * * 类是如何和事物进行对应的呢? * 类: * 成员变量 * 成员方法 ...
- vue-resource安装与使用
vue-resource是vue中使用的请求网络数据的插件,这个插件是依赖于vue的,简单说就是用来调接口的. 安装 cd 项目目录 npm i vue vue-resource --save-dev ...
- "字体图标"组件:<icon> —— 快应用组件库H-UI
 <import name="icon" src="../Common/ui/h-ui/basic/c_icon"></import> ...
- centos7安装puppet详细教程(简单易懂,小白也可以看懂的教程)
简介: Puppet是一种linux.unix平台的集中配置管理系统,使用ruby语言,可配置文件.用户.cron任务.软件包.系统服务等.Puppet把这些系统实体称之为资源,它的设计目标是简化对这 ...
- Java课程设计之——爬虫篇
主要使用的技术 Httplcient Jsoup 多线程 dao模式 网络爬虫简介 网络爬虫(又称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取 ...
- [总结]RMQ问题&ST算法
目录 一.ST算法 二.ST算法の具体实现 1. 初始化 2. 求出ST表 3. 询问 三.例题 例1:P3865 [模板]ST表 例2:P2880 [USACO07JAN]平衡的阵容Balanced ...
- Docker-CentOS系统安装Docker
上一节,我们介绍了安装虚拟机及操作系统,本文再详细描述安装docker的命令. 前提条件 虚拟机系统:CentOS,并且虚拟机能连通外网. 另外,虚拟机最好配置上阿里的镜像源,点此链接,进入cento ...
- Jmeter接口测试、性能测试详细介绍
下面主要就是讲一下Jmeter工具的用法,用法非常简单,比起loadrunner不知道简单多少,并且开源免费~~ 1.接口简介 接口定义 接口: 就是数据交互的入口和出口,是一套标准规范. 接口(硬件 ...