题目链接:

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. python 3.4 装matplotlib numpy

    为了装个matplotlib包,搞了好久:   python3.4,官方没有对应版本的包,只能去下面这个地方下对应的版本: http://www.lfd.uci.edu/~gohlke/pythonl ...

  2. Ibatis的分页机制的缺陷

    我们知道,Ibatis为我们提供了可以直接实现分页的方法 queryForList(String statementName, Object parameterObject, int skipResu ...

  3. sencha touch笔记(6)——路由控制(1)

    做项目的时候在界面的跳转上遇到了挺大的问题,本来跳转不想通过路由来控制的,没办法,只能再去看一下路由的跳转方式了. 应用程序的界面发生改变后,可以通过路由让应用程序的界面返回到改变之前的状态,例如浏览 ...

  4. 用eclipse编写Android程序时怎样生成apk文件

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/16828449 APK是Android Package的缩写,即Android安装包.通过将 ...

  5. 墙内安装nautilus-dropbox 1.6.0-2

    软件包:nautilus-dropbox 版本号:1.6.0-2 # aptitude install nautilus-dropbox # less `which dropbox` 查找到下载链接: ...

  6. 基于visual Studio2013解决C语言竞赛题之0808打印链表

     题目

  7. Js内存泄露问题总结

    最近接受了一个Js职位的面试,问了很多Js的高级特性,才发现长时间使用已知的特性进行开发而忽略了对这门语言循序渐进的理解,包括Java我想也是一样,偶尔在Sun官方看到JDK6.0列举出来的new f ...

  8. ASP.NET中操作SQL数据库

    在WebConfig中配置数据库连接字符串,代码如下: <connectionStrings>         <add name="ConnectionString&qu ...

  9. STM32 控制步进电机 28BYJ-48

    STM32 控制步进电机 28BYJ-48  http://blog.chinaunix.net/uid-12664992-id-300272.html 步进电机驱动最简化的逻辑: //四相八拍:A- ...

  10. android studio 怎么运行java

    方法/步骤 1.新建一个project,或者如果已经有project的话,那就直接新建一个module.注意选择Java library,然后下一步 2.输入module的一些信息.点击finish ...