poj1862 Stripies

思路:

简单贪心。

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cmath>
 5 using namespace std;
 6
 7 int a[105], n;
 8
 9 bool cmp(const int & a, const int & b)
10 {
11     return a > b;
12 }
13
14 int main()
15 {
16     cin >> n;
17     for (int i = 0; i < n; i++)
18     {
19         cin >> a[i];
20     }
21     sort(a, a + n, cmp);
22     double res = a[0];
23     for (int i = 0; i < n - 1; i++)
24     {
25         res = 2.0 * sqrt(res * a[i + 1]);
26     }
27     printf("%.3f\n", res);
28     return 0;
29 }
时间: 2024-08-06 11:35:24

poj1862 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

poj1862(Stripies)贪心

Description 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 str

POJ 1862 &amp; ZOJ 1543 Stripies(贪心 | 优先队列)

题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=543 Description Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian -

POJ 1862 Stripies 贪心+优先队列

http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成一个的最小重量 思路: m1+m2 >=  2*sqrt(m1*m2) 所以每次取大的去合并,能变小. 直接优先队列就可以啦. #include<cstdio> #include<cmath> #include<queue> using namespace std;

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 tr

POJ 1862 Stripies【哈夫曼/贪心/优先队列】

Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18198   Accepted: 8175 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

POJ 1862 Stripies 题解 《挑战程序设计竞赛》

题目:POJ - 1862 思路:每次挑选最大的两个数,进行2*sqrt(a,b)运算后放入到队列中.有点类似于之前做的fence repair题目. 这样可以保证大数被开方的次数更多,最后的结果更小. 注意: n为1的情况,WA了几次. 学会C++输出格式控制: http://c.biancheng.net/cpp/biancheng/view/2227.html. 1 #include <iostream> 2 #include <stdio.h> 3 #include <

9 POJ 1862 Stripies 简单贪心

观察发现m1+m2变为2*sqrt(m1*m2)质量是能够减少的, 因此按质量从大到小排序,每次取最大质量的两个合并,减少的质量是最多的. 合并n-1次,最终得到的一个数就是结果. 这里用优先队列写的比较方便. #include<cstdio> #include<queue> #include<cmath> using namespace std; priority_queue<double> q; int main() { int n,i; double

poj1862

水题一个,就是永远先用最大的数碰撞 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int maxn=100+10; double a[maxn]; int main() { int n; scanf("%d",&n); fo