POJ 1862 & ZOJ 1543 Stripies(贪心 | 优先队列)
题目链接:
PKU:http://poj.org/problem?id=1862
ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=543
Description
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
Output
Sample Input
3
72
30
50
Sample Output
120.000
Source
题意:
就是有一些细胞条纹,他们会碰撞,碰撞后会变为一个新的细胞条纹,碰撞后的重量依照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 & ZOJ 1543 Stripies(贪心 | 优先队列)的更多相关文章
- POJ 1862 Stripies 贪心+优先队列
http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...
- 【POJ - 3190 】Stall Reservations(贪心+优先队列)
Stall Reservations 原文是English,这里直接上中文吧 Descriptions: 这里有N只 (1 <= N <= 50,000) 挑剔的奶牛! 他们如此挑剔以致于 ...
- poj 1862 Stripies/优先队列
原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...
- POJ1862 Stripies 贪心 B
POJ 1862 Stripies https://vjudge.net/problem/POJ-1862 题目: Our chemical biologists have invented ...
- hihoCoder 1309:任务分配 贪心 优先队列
#1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN, ...
- UVA 11134 - Fabled Rooks(贪心+优先队列)
We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrict ...
- 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 ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解
思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...
随机推荐
- 数据库迁移 - SQLServer->MySQL
SqlServer转换为Mysql的一款工具推荐(mss2sql)
- android的四种加载模式
在Android中每个界面都是一个Activity,切换界面操作其实是多个不同Activity之间的实例化操作.在Android中Activity的启动模式决定了Activity的启动运行方式. An ...
- React.js学习
React.js学习之环境搭建 1 工欲善其事必先利其器:前端开发工具 1.1 WebStorm和Sublime Text Sublime Text:作为代码编辑器,Sublime Text的优点如下 ...
- Ajax技术——带进度条的文件上传
1.概述 在实际的Web应该开发或网站开发过程中,经常需要实现文件上传的功能.在文件上传过程中,经常需要用户进行长时间的等待,为了让用户及时了解上传进度,可以在上传文件的同时,显示文件的上传进度条.运 ...
- github上的QT源码,必要的时候还是应该看一下,仅凭猜测很容易出错
QCoreApplication::processEvents 他处理的时候拿的是current不是qAppqApp的话,才是和主线程密切相关的 一直觉得QT源码复杂,有点怕,所以没怎么看 我也看不懂 ...
- 『WPF』DataGrid的使用
原文 『WPF』DataGrid的使用 几点说明 这里主要是参考了MSDN中关于DataGrid的说明 这里只会简单说明在WPF中,DataGird最简单的使用方法 对于MSDN中的翻译不会很详细,也 ...
- 基于visual Studio2013解决面试题之1102合并字符串
题目
- mysql数据导出权限问题
mysql数据导出的方法有非常多,比如mysqldump, mysql -e 'sql' > file, 这些都能够非常方便的导出数据,但是在使用普通用户导出数据的时候,出现了问题. 1 sel ...
- Android Content Provider的启动过程源码分析
本文參考Android应用程序组件Content Provider的启动过程源码分析http://blog.csdn.net/luoshengyang/article/details/6963418和 ...
- 硬盘被误格式化或Ghost还原后的数据恢复
硬盘格式化(Ghost还原)后的数据恢复 ---diskgenius使用之数据恢复 问题引出:计算机中病毒后用Ghost版本的winxp安装,由于安装途中选择了把映像安装到硬盘而不是分区,安装好后只剩 ...