POJ1862 Stripies 贪心 B
POJ 1862 Stripies
https://vjudge.net/problem/POJ-1862
题目:
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
Output
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的更多相关文章
- (贪心和优先队列) POJ1862 Stripies
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21506 Accepted: 9478 Descrip ...
- poj1862 Stripies
思路: 简单贪心. 实现: #include <iostream> #include <cstdio> #include <algorithm> #include ...
- POJ 1862 Stripies#贪心(水)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...
- POJ 1862 Stripies 贪心+优先队列
http://poj.org/problem?id=1862 题目大意: 有一种生物能两两合并,合并之前的重量分别为m1和m2,合并之后变为2*sqrt(m1*m2),现在给定n个这样的生物,求合并成 ...
- 《挑战程序设计竞赛》2.2 贪心法-其它 POJ3617 3069 3253 2393 1017 3040 1862 3262
POJ3617 Best Cow Line 题意 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作: 从S的头部(或尾部)删除一个字符,加到T的尾部 ...
- 【POJ - 1862】Stripies (贪心)
Stripies 直接上中文了 Descriptions 我们的化学生物学家发明了一种新的叫stripies非常神奇的生命.该stripies是透明的无定形变形虫似的生物,生活在果冻状的营养培养基平板 ...
- POJ 1862 & ZOJ 1543 Stripies(贪心 | 优先队列)
题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- 【POJ】1862:Stripies【贪心】【优先队列】
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20456 Accepted: 9098 Descrip ...
- POJ_1862 Stripies 【贪心】
一.题面 POJ1862 二.分析 反省一下,自己英语水平着实不行,该题其实就是问若给出若干个这种生物,根据这种体重变换方式,最终合并成一个后,体重最少是多少.根据公式 $m = 2\sqrt{m_{ ...
随机推荐
- mysqli字符编码
mysqli 字符编码: 汉字编码: 1.gbk 最久的编码格式,不能写繁体: 2.国内的gb2312: 3.国际的标准:utf-8; 查看数据库的字符编码: show variables like ...
- psi
purchase 采购sales 销售inventory 库存 outstock/instock/inventory taking outstock/instock/inventory 出库 入库 盘 ...
- Java 四种引用介绍及使用场景
强引用-FinalReference 介绍: 强引用是平常中使用最多的引用,强引用在程序内存不足(OOM)的时候也不会被回收,使用方式: String str = new String("s ...
- 到底什么是哈希Hash?
知识点总结 ---------------------------------------------------------------------------------------------- ...
- windows密码策略
windows域环境配置密码策略: http://www.cnblogs.com/danzhang/p/3693024.html windows配置密码策略: https://jingyan.baid ...
- python使用细节
python的函数位置参数在调用时可以直接传参,也可以a=5,b=7的形式传参,原以为kw参数才可以. >>> def f(a,b): print a+b >>> ...
- leetcode98
class Solution { public: vector<int> V; void postTree(TreeNode* node) { if (node != NULL) { if ...
- UI5-培训篇-Fiori培训
1.学习网站: SAPUI5学习地址: https://blog.csdn.net/stone0823/article/category/6650292/1? SAPUI5文档: https://sa ...
- Python oracle乱码问题
Python使用cx_oracle连接oracle查询汉字时出现乱码 解决方式: import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHIN ...
- MySQL 物理文件体系结构的简单整理说明
本文出处:http://www.cnblogs.com/wy123/p/7102128.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...