[挑战程序设计竞赛] POJ 1862 - Stripies

题目大意:有一种生物两个遇到后会合成一个,质量为2sqrt(m1*m2),给你一些这种生物的质量,问合成的最小质量为多少。
题目链接
这题是贪心题,根据样例,跑了跑,发现两个较大的数先合并最后得到的结果是最小的,于是猜想,是不是采取每次都从剩余生物里面取出质量较大的两个,一直合并知道最后只剩余一个生物取得的结果就是最小的呢?这需要数学证明,而我将要在下面做这件事。
1:考虑n<=2的情况,直接输出;
2:重点证明当n==3时:不妨设存在三个物体a,b,c,(a 对于ac:w = 2 * sqrt( 2 * sqrt( a * c ) * b ) ;
对于bc:w = w = 2 * sqrt( 2 * sqrt( b * c ) * b )
因为a1 ⇒ pow(b/a,2)> b/a ⇒b/a>sqrt(b/a) ⇒ sqrt(b) * a 结论:对于最先选择的数据和其他任一个组合相比,其中必有一个数是相同的,另外一个数大的最后的结果肯定更小⇒bc < ac < ab(因为 b>a,c>b);
3:考虑n>3的情况:不写了,赶计网作业去了;
注意:printf 没有lf 没有lf 没有 lf

/*
* File: GreedyTraining_E.c
* Author: Jiawen Bao
* Date: 20190422
*
* Purpose: to solve a problem in vjudge:
* https://vjudge.net/contest/296756#problem/E
*/

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define REP(i,n) for(int i=0;i MII;
typedef map MSI;
typedef vector VI;
typedef vector VS;
typedef vector VD;
typedef pair PII;
typedef long long LL;
typedef unsigned int UI;
typedef long double LD;
typedef unsigned long long ULL;

int main(){
	int N;
	cin>>N;
	vector w(N,0);
	for(int i=0;i>w[i];
	}
	sort(w.begin(),w.end());
	double ans = w[N-1],max = ans;
	for(int i=N-2;i>=0;i--){
		ans = 2*sqrt(max*w[i]);
		max = ans;
	}
	printf("%.3f\n",ans);
//	cout<<2*sqrt(2*sqrt(30*50)*72)<

你可能感兴趣的:(世界你好)