POJ 1862 Stripies

https://vjudge.net/problem/POJ-1862

题目:

    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(m1*m2). 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 of the input 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 three decimal digits after the point.

Sample Input


Sample Output

120.000

分析:

贪心题目

题目本身不难,总共就几种策略,WA几发蒙也能蒙过了

问题在于这个题为什么这么做是正确的

我在做的时候就顺便用txt进行了证明,毕竟是练习,也为了保证一遍过

首先写了这个,然后意识到不是相加,是直接把v1和v2变成另外一种,所以这是错误的

然后列了几种情况,当两个数的时候,产生的结果是不固定的,可能大,可能小,也可能与其中一个相等,这里就可以想到用增加变量然后用字母来代替数值进行分析

V1v2v3

然后进行第一步,如果12合并,如果23合并,如果13合并

一行一个情况

在这其中保证

那么最后的三个结果就是

看起来比较复杂emmmm

那就简单化简吧,假设第一个和第二个相等

化简

然后取平方

诶是不是发现什么了

都会有

这个东西,

唯一的区别是v1,v2,v3

那么显然是

倒推:

得证

放全部分析过程:

v1+v2 -> 2*sqrt(v1*v2)

sqrt(v1^2+v2^2+2*v1*v2) -> sqrt(4*v1*v2)

1 100

20

72 50

120

2 50

20

5 20

20

v1 v2 v3

2*sqrt(v1*v2) v3

2*sqrt(v1*v3) v2

2*sqrt(v2*v3) v1

v1<v2<v3

2*sqrt(2*sqrt(v1*v2)*v3)

2*sqrt(2*sqrt(v1*v3)*v2)

2*sqrt(2*sqrt(v2*v3)*v1)

2*sqrt(2*sqrt(v1*v2)*v3)=2*sqrt(2*sqrt(v1*v3)*v2)

sqrt(v1*v3)*v2=sqrt(v1*v2)*v3

v1*v2*v3*v3  v1*v3*v2*v2

v1*v2*v3

v1*v2*v3*v1 min

也就是sqrt(v2*v3)*v1

再倒推就是2*sqrt(2*sqrt(v2*v3)*v1)

再倒推就是先处理两个大的

得证

AC代码:

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
double a[];
bool cmp(double a, double b){
return a > b;
}
int main() {
int n = ;
s(n);
for(int i = ; i < n; i ++){
slf(a[i]);
}
sort(a,a+n,cmp);
double temp = a[];
for(int i = ; i< n ;i ++){
temp = 2.0*sqrt(a[i]*temp);
}
pf("%.3lf\n",temp);
return ;
}

POJ1862 Stripies 贪心 B的更多相关文章

  1. (贪心和优先队列) POJ1862 Stripies

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21506   Accepted: 9478 Descrip ...

  2. poj1862 Stripies

    思路: 简单贪心. 实现: #include <iostream> #include <cstdio> #include <algorithm> #include ...

  3. POJ 1862 Stripies#贪心(水)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...

  4. POJ 1862 Stripies 贪心+优先队列

    http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...

  5. 《挑战程序设计竞赛》2.2 贪心法-其它 POJ3617 3069 3253 2393 1017 3040 1862 3262

    POJ3617 Best Cow Line 题意 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作: 从S的头部(或尾部)删除一个字符,加到T的尾部 ...

  6. 【POJ - 1862】Stripies (贪心)

    Stripies 直接上中文了 Descriptions 我们的化学生物学家发明了一种新的叫stripies非常神奇的生命.该stripies是透明的无定形变形虫似的生物,生活在果冻状的营养培养基平板 ...

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

    题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  8. 【POJ】1862:Stripies【贪心】【优先队列】

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20456   Accepted: 9098 Descrip ...

  9. POJ_1862 Stripies 【贪心】

    一.题面 POJ1862 二.分析 反省一下,自己英语水平着实不行,该题其实就是问若给出若干个这种生物,根据这种体重变换方式,最终合并成一个后,体重最少是多少.根据公式 $m = 2\sqrt{m_{ ...

随机推荐

  1. vue1 & vue2 数据驱动更新视图机制对比

    vue1 小粒度更新,精确追踪到数据变化所影响的dom变化,精确更新变化的dom 具体实现为,维护 observer watcher directive 三个类 ·observer负责监听数据变化,并 ...

  2. Spring系列博客汇总

    https://www.cnblogs.com/leeSmall/category/1093236.html   springmvc https://www.cnblogs.com/leeSmall/ ...

  3. 深入了解scanf()/getchar()和gets()/cin等函数

    转:http://www.cnblogs.com/FCWORLD/archive/2010/12/04/1896511.html 转:问题描述一:(分析scanf()和getchar()读取字符) s ...

  4. 团队第三次 # scrum meeting

    github 本此会议项目由PM召开,召开时间为4-7日晚上9点 召开时长15分钟 任务表格 袁勤 继续学习SpringBoot https://github.com/buaa-2016/phyweb ...

  5. java多线程—Runnable、Thread、Callable区别

    多线程编程优点 进程之间不能共享内存,但线程之间共享内存非常容易. 系统创建线程所分配的资源相对创建进程而言,代价非常小. Java中实现多线程有3种方法: 继承Thread类 实现Runnable接 ...

  6. Oracle 循环查询

    select * from sys_department start with departmentid = '0303e461-2454-4d5a-bfea-2cd5a4c064c6' connec ...

  7. CPU与内存互联的架构演变

    随着计算机中CPU核数目的增加,传统的UMA(unifonn memory access)架构由于对关键硬件(如中央内存控制器)的竞争加剧出现了性能上的瓶颈,即扩展性不强.而NUMA架构则以其良好的可 ...

  8. 微信小程序---人脸识别(wx.startFacialRecognitionVerify)

    1.由于人脸核验功能涉及到用户的敏感.隐私信息,因此调用此接口的业务方,需要满足一定的条件,申请小程序的人脸识别api.开通小程序后台的接口权限入口后,开发者可以登录mp.weixin.qq.com小 ...

  9. 获取当前页面url

    function getCurrUrl() { var url = ""; if (parent !== window) { try { url = window.top.loca ...

  10. JS全局对象的属性

    全局对象是最顶层的对象,在浏览器环境指的是window对象.在ES5中,全局对象的属性与全局变量是等价的. var str = "hello"; function test(){ ...