首页 > 其他分享 >Stripies POJ-1862

Stripies POJ-1862

时间:2022-09-02 20:44:35浏览次数:83  
标签:int 1862 sqrt times Stripies POJ pop heap include

题目链接

思路

首先,先将出思路:每次取出较大的数进行合并,最后的结果最小
证明:

假设一共有 \(3\) 个数 \(a,b,c\) 和最后的答案 \(w\)
将 \(a,b,c\) 进行排列后答案 \(w\) 就可以表示为 \(2 \times \sqrt{2 \times a \times \sqrt{b \times c}}\)
经过等式变换后可得 \(w^2/8 = a^2 \times \sqrt{b * c}\) ,由于 \(a\) 的指数是最大的,所以最后一个合并的数要尽可能的小,所以要从大到小合并。

代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
using namespace std;
int n;
priority_queue <double,vector <double>,less <double> > heap;
int main () {
	cin >> n;
	for (int i = 1;i <= n;i++) {
		int x;
		cin >> x;
		heap.push (x);
	}
	while (heap.size () > 1) {
		double a = heap.top ();heap.pop ();
		double b = heap.top ();heap.pop ();
//		cout << a << ' ' << b << endl;
		double t = 2 * sqrt (a * b);
		heap.push (t);
	}
	printf ("%.3lf",heap.top ());
	return 0;
}

标签:int,1862,sqrt,times,Stripies,POJ,pop,heap,include
From: https://www.cnblogs.com/incra/p/16651173.html

相关文章

  • SPOJ-GRAFFDEF King Graffs Defense
    KingGraffsDefensetarjan割边显然如果是割边的话,边两边的边双连通分量就不能连通因此考虑\(dfs\)搜索树中,计算出所有边双连通分量的大小,然后每个边双连通分量与其......
  • [POJ1062]昂贵的聘礼题解
    [POJ1062]昂贵的聘礼题目链接【题目大意】现有n个物品,每个物品价格为vi,同时可以用其他物品减免价格(当然,你必须拥有该物品).问如何购买可以使得到物品1的花费最少.此外,还......
  • SPOJ-EC_P Critical Edges
    CriticalEdgestarjan割边模板#include<iostream>#include<cstdio>#include<algorithm>#include<vector>usingnamespacestd;#definepiipair<int,int>con......
  • 「POJ1475」Pushing Boxes 题解
    「POJ1475」PushingBoxes题解题目大意一张N行M列的地图,字符“.”表示空地,字符“#”表示墙,字符“S”表示人的起始位置,字符“B”表示箱子的起始位置,字符“T”表示箱子的......
  • POJ2287 Tian Ji -- The Horse Racing
    题目链接题目DescriptionHereisafamousstoryinChinesehistory.Thatwasabout2300yearsago.GeneralTianJiwasahighofficialinthecountryQi.He......
  • POJ2955 Brackets
    题目链接题目DescriptionWegivethefollowinginductivedefinitionofa“regularbrackets”sequence:theemptysequenceisaregularbracketssequence,ifs......