Timus 1161. Stripies

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(m1m2).
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 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 two decimal digits after the point.

Sample

input output
3
72
30
50
120.00

奇怪的数学题:

排序,然后由大到小合并。

这里使用点新东西,使用个multiset<double>容器来解决问题,这样连排序都省了。然后是倒序处理数组。

很好用的容器。

#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;

void Stripies1161()
{
	multiset<double> s;
	int n = 0;
	double a;
	cin>>n;
	for (int i = 0; i < n; i++)
	{
		cin>>a;
		s.insert(a);
	}
	auto it = s.rbegin();
	a = *it;
	for (it++; it != s.rend(); it++)
	{
		a = 2.0 * sqrt(a * (*it));
	}
	cout<<a;
}

Timus 1161. Stripies,码迷,mamicode.com

时间: 2024-11-07 21:01:01

Timus 1161. Stripies的相关文章

POJ1862 Stripies 【贪心】

Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12522   Accepted: 5929 Description Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, bu

51nod 1161 组合数,规律

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1161 显然,题目可以转化为矩阵求解,但复杂度显然时空都不允许,我们如果自己把这个N*N矩阵的前几项列出来的话就会发现和杨辉三角的某一部分相似, 对照一下发现这个矩阵的第一行对应的就是杨辉三角的某一斜列,依次向下递减,也就是说我们只要知道这几个组合数,就能推导出来这个矩阵. 对于每一个K,对应的矩阵首行元素就是 :  C(k-1,0),C(k,1),C(k+1,2)...

Timus 1049 Brave Balloonists

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1049 题目描述: 题目大意为给定10个数,然后求这10个数之积所对应的数的所有正因子的个数N的个位数. 那么直接对10个数进行质因数分解即可.(注意%10) 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 using namespace std ; 5 6 const int MAXM

Timus OJ 1057 数位dp

http://acm.timus.ru/problem.aspx?space=1&num=1057 1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactlyK different integer degrees of B.

timus 1547. Password Search【题意思路+大数模板】

题目地址传送门:URAL 1547 这道题需要用到大数的很多模板,推荐大家去刷刷! 题目大意:Vova忘记了在Timus OJ上面的密码了,密码是由小写字母(a~z)组成的,他只知道密码长度不大于n位,现在他需要用m台数据处理器对密码进行检索,其中检索顺序需要满足字典序.比如他的密码长度不大于2,那就需要依次检索a,b,..........,y,z,aa,ab,..........,zy,zz.输出每台数据检索器的检索区间,使得总的检索效率可以达到最高. 已知密码的总可能数不少于数据处理器个数.

Timus 2005. Taxi for Programmers 题解

The clock shows 11:30 PM. The sports programmers of the institute of maths and computer science have just finished their training. The exhausted students gloomily leave their computers. But there's something that cheers them up: Misha, the kind coach

Timus 2070 Interesting Numbers

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2070 题目描述: 题目大意是给定范围[L, R],求该范围中interesting数的个数. interesting数的定义为: 1.素数 2.不为素数且其正因子的个数不为素数个(如:6: 1,2,3,6) 计算正因子的个数一般使用的是分解质因数了,若 n = p1^a1 * p2^a2 * ... pm^am 那么正因子的个数为 k = (a1+1) * (a2+1) * ... * (am

HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following method: 1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only c

timus 1613. For Fans of Statistics【该题超时的代码记录】

该题的意思:按编号递增给出n(0<n<70000)个点的值(点的编号从1~n),给出m(1<=m<70000)条查询数据 数据输入格式为a b c(从编号a到编号b之间是否有值是为c的,如果有则返回1,没有返回0 具体的意思可以进链接: http://acm.timus.ru/problem.aspx?space=1&num=1613 这里只给出超时的代码(可能这道题C++解决真的得用上STL): case 1: /* 树的子节点最多三个 左边的子节点(left)表示小于根