题目链接:

PKU:http://poj.org/problem?id=1862

ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=543

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 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. 

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

Source

Northeastern Europe 2001, Northern Subregion

题意:

就是有一些细胞条纹,他们会碰撞,碰撞后会变为一个新的细胞条纹,碰撞后的重量依照2*sqrt(m1*m2)计算,问最后的最小重量;

PS:

開始半天没读懂题意;

代码一例如以下:(贪心)

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int n;
int a[117];
while(~scanf("%d",&n))
{
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
double tt = a[n-1];
for(int i = n-2; i >= 0; i--)
{
tt = 2*sqrt(tt*a[i]);
}
printf("%.3lf\n",tt);
}
return 0;
}

代码二例如以下:(优先队列)

#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int n;
double a, b, c, tt;
priority_queue<double,vector<double>,less<double> > Q;
while(~scanf("%d",&n))
{
while(!Q.empty())
{
Q.pop();
}
for(int i = 0; i < n; i++)
{
scanf("%lf",&a);
Q.push(a);
}
for(int i = 0; i < n-1; i++)
{
b = Q.top();
Q.pop();
c = Q.top();
Q.pop();
tt = 2*sqrt(b*c);
Q.push(tt);
}
printf("%.3f\n",Q.top());
}
return 0;
}

POJ 1862 &amp; ZOJ 1543 Stripies(贪心 | 优先队列)的更多相关文章

  1. POJ 1862 Stripies 贪心+优先队列

    http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...

  2. 【POJ - 3190 】Stall Reservations(贪心+优先队列)

    Stall Reservations 原文是English,这里直接上中文吧 Descriptions: 这里有N只 (1 <= N <= 50,000) 挑剔的奶牛! 他们如此挑剔以致于 ...

  3. poj 1862 Stripies/优先队列

    原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...

  4. POJ1862 Stripies 贪心 B

    POJ 1862 Stripies https://vjudge.net/problem/POJ-1862 题目:     Our chemical biologists have invented ...

  5. hihoCoder 1309:任务分配 贪心 优先队列

    #1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN,  ...

  6. UVA 11134 - Fabled Rooks(贪心+优先队列)

    We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrict ...

  7. C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列

    C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  8. POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)

    POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...

  9. HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解

    思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...

随机推荐

  1. unix网络编程之listen()详解

    转自于:http://blog.csdn.net/ordeder/article/details/21551567 Unix网络编程描述如下: #include <sys/socket.h> ...

  2. 菜鸟学习SSH(二)——Struts国际化

    国际化(internationalization,i18n)和本地化(localization,l10n)指让产品(出版物,软件,硬件等)能够适应非本地环境,特别是其他的语言和文化.程序在不修改内部代 ...

  3. awk 的逻辑运算字符

    既然有需要用到 "条件" 的类别,自然就需要一些逻辑运算啰-例如底下这些:运算单元代表意义> 大于小于>= 大于或等于小于或等于== 等于!= 不等于值得注意的是那个 ...

  4. MyPanel与QWidget使用QStyle设置背景色的不同

    -----------   MainWindow.h ------------------- class MyPanel: public QWidget{    Q_OBJECTpublic:     ...

  5. Step by step guide to set up master and slave machines(转)

    Note: There is no need to install Jenkins on the slave machine. On your master machine go to Manage ...

  6. Android Drawable 与 LayerList综合汇总

    先看需求.要求这样的效果 上代码 <?xml version="1.0" encoding="utf-8"? > <layer-list xm ...

  7. Swift - 如何实现字符串的HMAC_SHA1加密

    前段时间有个网友问是否有Swift的HMAC_SHA1算法.这次就专门写篇相关文章进行介绍.要说明HMAC-SHA1,首先要先了解什么是HMAC,什么是SHA. 1,HMAC(散列消息身份验证码:Ha ...

  8. Android---60---Notification 通知栏的简单使用

    Notification是显示在手机状态栏的通知 通过Notification.Builder类创建Notification对象. Notification.Builder经常用法: setDefau ...

  9. Java基础08 继承

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 继承(inheritance)是面向对象的重要概念.继承是除组合(composit ...

  10. Java Socket实现HTTP客户端来理解Session和Cookie的区别和联系

    HTTP协议本身是无状态的,即使是同一台电脑同一个浏览器打开同一个页面两次,服务器不知道这两次请求是同一个客户端发送过来的,两次请求是完全独立的.例如,第一次请求时已经登录了,第二次再请求服务器会“忘 ...