题目链接:

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;
}

转载于:https://www.cnblogs.com/zfyouxi/p/4209207.html

POJ 1862 amp; ZOJ 1543 Stripies(贪心 | 优先队列)相关推荐

  1. zoj 1543 Stripies

    简单贪心. 类似哈夫曼树,排序后,从最大的两个计算后最为初值从最大的挨着算. 为什么这么算呢? 我开始是蒙的,居然对了,汗.因为这样吧如果大的作为先前计算的结果,那么后面它会经过很多次sqrt这样的话 ...

  2. poj 1862 Stripies/优先队列

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

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

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

  4. 1163 最高的奖励(贪心+优先队列)

    有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励.在结束时间之前完成该任务,就可以获得对应的奖励.完成每一个任务所需的时间都是1个单位时间.有时候完成所有任务是不可能的,因为时间上可能会有冲突 ...

  5. 贪心+优先队列 HDOJ 5360 Hiking

    题目传送门 1 /* 2 题意:求邀请顺序使得去爬山的人最多,每个人有去的条件 3 贪心+优先队列:首先按照l和r从小到大排序,每一次将当前人数相同的被邀请者入队,那么只要能当前人数比最多人数条件小, ...

  6. 贪心(优先队列) - New Year Snowmen - CodeForces - 140C

    贪心(优先队列) - New Year Snowmen - CodeForces - 140C 题意: 给定一个长度为n的正整数序列a1,a2,...,an.给定一个长度为n的正整数序列a_1,a_2 ...

  7. CodeForces 140C New Year Snowmen (贪心+优先队列)

    题意:n个数,选三个严格下降的数为一组,求最多能选多少组,并列出每组哪些数. 题解:贪心+优先队列 最多能选多少组,那么必须贪心数量多的. 例如:1 1 2 3 4 5 如果按照数的大小排序,只能贪到 ...

  8. CF140C New Year Snowmen(贪心+优先队列)

    CF140C 贪心+优先队列 贪心策略:每次取出数量最多的三种球,合成一个答案,再把雪球数都-1再插回去,只要还剩下三种雪球就可以不断地合成 雪球数用优先队列维护 #include <bits/ ...

  9. 【BHOJ 女娲加农炮 |、||】贪心 | 优先队列 | 堆 | E

    这次我们通过两道例题来总结一下优先队列的用法和实现: 目录: [BHOJ 1512]女娲加农炮 [BHOJ 1517]女娲加农炮II [BHOJ 1512]女娲加农炮 核心:贪心 + 优先队列 URL ...

最新文章

  1. [SAP PI]ECC系统接收财务凭证IDoc的配置步骤(总账 应收 应付)
  2. python数据处理框架_python 最快 web 框架 Sanci 快速入门
  3. 【Python】列表推导式求 100 以内的所有素数
  4. NUMA - Non Uniform Memory Architecture 非统一内存架构
  5. java关键字只static
  6. iOS:Resource Programming Guide
  7. ubunt18 mysql_Ubuntu18.04下安装MySQL教程
  8. MySQL驱动包下载
  9. jupyter添加新的语言包
  10. 花生壳内网穿透+https+tomcat不能进行网页访问
  11. 高端门诊提示预约体检短信怎么发?
  12. 部落冲突-家乡防御建筑-箭塔(1级至20级)
  13. 【PCB】Altium Designer PCB规则配置
  14. DM36x 接入 AR0130 sensor
  15. Mac 系统下Python多版本管理
  16. 手机游戏运行时分析工具
  17. Gmail代理收发邮件
  18. vue 给iframe设置src_vue 中引入iframe,动态设置其src,遇到的一些小问题总结
  19. 联盟服务器维护,英雄联盟维护时间 lol官网服务器维护公告
  20. C#制作activeX控件

热门文章

  1. Java Micro services: 传送唯一标识(request id)在Hessian call, rest API,JMS和Thread之间
  2. 判断php图片是否存在,php判断远程图片是否存在
  3. 程序员必备工具包(实物)
  4. Map排序,获取map的第一值,根据value取key等操作(数据预处理)
  5. 网络爬虫之httpclient的使用
  6. Django--模板语言
  7. 【小程序】【Tips】【实践】Json 的对象 和 Json字符串 的区别和转换
  8. mysql索引 红黑树_为什么MySql索引使用B+树?
  9. jquery 页面滚动条回到顶部_jquery懒加载、回到顶部
  10. 挑选出tensor中等于0的索引_Pytorch中的5个非常有用的张量操作