【POJ - 1862】Stripies (贪心)
Stripies
直接上中文了
Descriptions
Input
Output
Sample Input
3
72
30
50
Sample Output
120.000
Hint
样例解释:
72与50合并,产生120,120与30合并,产生120
题目链接
https://vjudge.net/problem/POJ-1862
贪心算法,2*sqrt(m1*m2) 有这个式子易得m1和m2应该每次都是这个数组里最大的两个数,想到这就简单了,每次排个序就行了
AC代码
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100000+100
using namespace std;
int n;
double m[Maxn];
bool cmp(double x,double y)//m数组按从大到小排序
{
return x>y;
}
double fun(double m1,double m2)//题目要求的函数
{
return *sqrt(m1*m2);
}
int main()
{
cin>>n;
for(int i=;i<n;i++)
cin>>m[i];
sort(m,m+n,cmp);//排序
while(m[]!=)
{
m[]=fun(m[],m[]);//更新
m[]=;
sort(m,m+n,cmp);
// 不懂的看一加上下面的注释看一下里面的操作
// for(int i=0;i<n;i++)
// cout<<m[i]<<" ";
// cout<<endl;
}
printf("%.3f\n",m[]);
return ;
}
【POJ - 1862】Stripies (贪心)的更多相关文章
- POJ 1862 Stripies 贪心+优先队列
http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...
- POJ 1862 Stripies#贪心(水)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...
- POJ 1862 Stripies【哈夫曼/贪心/优先队列】
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18198 Accepted: 8175 Descrip ...
- poj 1862 Stripies/优先队列
原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...
- POJ 1862 Stripies (哈夫曼树)
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10263 Accepted: 4971 Descrip ...
- STL 训练 POJ - 1862 Stripies
Description Our chemical biologists have invented a new very useful form of life called stripies (in ...
- POJ 1862 Stripies
每次合并最大的两个,优先级队列维护一下. 输出的时候%.3lf G++会WA,C++能AC,改成%.3f,都能AC. #include<cstdio> #include<cstrin ...
- POJ 1862 Stripies 【优先队列】
题意:科学家发现一种奇怪的东西,他们有重量weight,如果他们碰在一起,总重变成2*sqrt(m1*m2).要求出最终的重量的最小值. 思路:每次选取质量m最大的两个stripy进行碰撞结合,能够得 ...
- POJ1862 Stripies 贪心 B
POJ 1862 Stripies https://vjudge.net/problem/POJ-1862 题目: Our chemical biologists have invented ...
- POJ 1862 & ZOJ 1543 Stripies(贪心 | 优先队列)
题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
随机推荐
- Java基础篇01
01. 面向对象 --> 什么是面向对象 面向对象 面向对象程序设计,简称OOP(Object Oriented Programming). 对象: 指人们要研究的任何事物,不管是物理上具体的事 ...
- Codeforces Round #569 (Div. 2)A. Alex and a Rhombus
A. Alex and a Rhombus 题目链接:http://codeforces.com/contest/1180/problem/A 题目: While playing with geome ...
- Codeforces Round #565 (Div. 3) A
A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...
- 13 | 效率为王:脚本与数据的解耦 + Page Object模型
- 用.NET Core实现一个类似于饿了吗的简易拆红包功能
需求说明 以前很讨厌点外卖的我,最近中午经常点外卖,因为确实很方便,提前点好餐,算准时间,就可以在下班的时候吃上饭,然后省下的那些时间就可以在中午的时候多休息一下了. 点餐结束后,会有一个好友分享 ...
- ES6_08_Iterator遍历器
Iterator遍历器: 概念: iterator是一种接口机制,为各种不同的数据结构提供统一的访问机制 作用: 1.为各种数据结构,提供一个统一的.简便的访问接口: 2.使得数据结构的成员能够按某种 ...
- html手机自适应屏幕
<meta name="viewport" content="height=device-width, initial-scale=1.0, maximum-sca ...
- c++学习书籍推荐《深度探索C++对象模型》下载
百度云及其他网盘下载地址:点我 百度云及其他网盘下载地址:点我 编辑推荐 如果你是一位C++程序员,渴望对于底层知识获得一个完整的了解,那么这本<深度探索C++对象模型>正适合你 作者简介 ...
- 【题解】P2078 朋友-C++
题目传送门 这道题目就是一个模板并查集 但是!唯一不同的地方在于,这道题的编号有负数. C++的map你忘了吗!!!下表可以是任意类型. 所以把fa数组开成一个int->int的map就可以了 ...
- Python爬虫学习代码
[1]用一个简单的程序来显示Python的数字类型. code: class ShowNumType(object): def __init__(self): self.showInt() self. ...