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对收益 ...
 
随机推荐
- Web 应用程序项目 XXXX 已配置为使用 IIS。 无法访问 IIS 元数据库。您没有足够的特权访问计算机上的 IIS 网站。(转载)
			
Web 应用程序项目 XXXX 已配置为使用 IIS. 无法访问 IIS 元数据库.您没有足够的特权访问计算机上的 IIS 网站. 2012年05月19日 ⁄ 综合 ⁄ 共 261字 ⁄ 字号 小 中 ...
 - 09-UIKit(UICollectionViewController、UITabBarController)
			
目录: 一.UICollectionViewController 二.UITabBarController(标签控制器) 三.视图和试图控制器的生命周期 四.其他控件 回到顶部 一.UICollect ...
 - QSettings保存程序设置
			
今天看了一些QSettings的简单用法,可以用来保存程序的设置,使得程序每次启动都可以显示上次关闭时的状态.我这里实现了一个简单的文本编辑窗口,可以设置文本的字体,字体的颜色和背景色.每次关闭程序都 ...
 - android用户界面之ScrollView教程实例汇总
			
--------------------------汇总不容易啊------------------------------- 一.ScrollView基础知识 1.Android中ScrollVie ...
 - Java I/O流-PipedInputStream、PipedOutputStream
			
一.整体代码图 PipedStreamDemo.java import java.io.*; class PipedStreamDemo { public static void main(Strin ...
 - [Android系列—] 1. Android 开发环境搭建与Hello World
			
前言 開始之前先熟悉几个名词: SDK -- Software Development Kit, 软件开发工具包.这个词并不陌生, JDK,就是Jave Development Kit,相同对于And ...
 - JDK 安装环境配置(ubuntu)
			
在Ubuntu 上安装jdk,先去官网下载相对应的tar包 网址:(这是jdk1.8) http://www.oracle.com/technetwork/java/javase/downloads/ ...
 - winform利用代码将控件置于顶端底端
			
有时,我们可能动态的添加控件,并准备将其置于对顶层或最底层.实现的方法有两个: 一种方法是在WinForm窗体中使用Controls控件集的SetChildIndex方法,该方法将子控件设定为指定的索 ...
 - 深入浅出 消息队列 ActiveMQ(转)
			
一. 概述与介绍 ActiveMQ 是Apache出品,最流行的.功能强大的即时通讯和集成模式的开源服务器.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provide ...
 - iphone开发教程下载
			
iphone开发教程下载 3月份花了1个月研究ios 开发,看了几百页的iphone开发教程,累积了不少电子书,盘点一下 Beginning iPhone 4 Development: Explori ...