【水分配】codeforces 185B (#118 D)- Mushroom Scientists
来源:互联网 发布:淘宝客服推荐技巧用语 编辑:程序博客网 时间:2024/04/28 14:23
这是我有史以来过的第一道最不明所以的D题
我居然也能给这道题打上水题的标签……简直把自己帅到了~
所以专门给这道题写一个题解:
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates(x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula:. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equalsxa·yb·zc.
To test the metric of mushroom scientists, the usual scientists offered them a task: find suchx, y, z(0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point(x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task.
Note that in this problem, it is considered that 00 = 1.
The first line contains a single integer S(1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point.
The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists.
Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations.
A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than10 - 6. We think thatln(0) = - ∞.
31 1 1
1.0 1.0 1.0
32 0 0
3.0 0.0 0.0
我写的时候真心不知道这题题意是怎么个意思!!!
有能三遍之内读懂的大神请让我膜拜下……
当时我们几个人有几个不同的解释
1)令这两个式子相等的,和不超过S的x,y,z分别为多少
2)令第一个式子最大的,和不超过S的x,y,z分别为多少
3)令第二个式子最大的,和不超过S的x,y,z分别为多少 (我是这个理解)
4)令第二个式子的log值最大的,和不超过S的x,y,z分别为多少
吾辈为了枚举题意,尝试了一发按照比例分配S的代码,过了你敢信?……
如果a,b,c都为0,把S全都给a,然后bc为0,反之按比例给abc分配即可。
实际上——
若a,b,c中有一个为0,0的0次方为1,非0次方为0,那肯定得给他分配0啊。
非零的情况下,当指数按照底数的比例分配的时候,可以获得最大的乘积,这个可以通过斜率啊、微分啊什么的都可以证明的出来
Code:
#include <cmath>#include <cstdio>#include <iostream>using namespace std;int main(){ int S,a,b,c; cin>>S>>a>>b>>c; if( a+b+c==0 ){ cout<<S<<" 0 0"; return 0;} double x = double(a*S)/(a+b+c); double y = double(b*S)/(a+b+c);double z = double(c*S)/(a+b+c); printf("%.18lf %.18lf %.18lf", x, y, z); return 0;}
- 【水分配】codeforces 185B (#118 D)- Mushroom Scientists
- 【微积分】CodeForces 185B Mushroom Scientists
- CodeForces Round #118 - Mushroom Scientists
- codeforces 186D Mushroom Scientists 不等式
- Mushroom Scientists(Codeforce)
- Codeforces Round #118 (Div. 1) A Mushroom Scientists (多元函数极值问题+拉格朗日乘数法)
- Codeforces Round #118 (Div. 1) A Mushroom Scientists (多元函数极值问题+拉格朗日乘数法)
- Mushroom Scientists
- Codeforces-Educational Codeforces Round 32-(A,B,C,D)
- CodeForces 60 E.Mushroom Gnomes(矩阵快速幂)
- Codeforces Round #285 (Div. 2) (A、B、C、D)
- Codeforces Round #300 (A,B,C,D)
- Codeforces Round #301 (Div. 2) -- (A,B,C,D)
- Codeforces Round #313 (Div. 2) (A、B、C、D)
- Codeforces Round #364 (Div. 2)(A,B,C,D)
- CodeForces - 295B D - Greg and Graph(floyd算法)
- 【Codeforces Round #402 (Div. 2) 】(A,B,C,D )
- Codeforces Beta Round #99 (Div. 1) C Mushroom Gnomes - 2(单点查询)
- linux压缩和解压缩命令大全
- 算法设计学习:二叉树算法
- 韩顺平PHP学习视频笔记整理003html相关基础知识
- 另外五个 PHP 设计模式
- 九度 题目1049:字符串去特定字符
- 【水分配】codeforces 185B (#118 D)- Mushroom Scientists
- Eclipse中如何清除EGit记住的GitHub用户名和密码
- poj1011
- leetCode Linked List Cycle 解题分享
- CentOS简洁安装OpenLDAP
- 阶乘因式分解(二)
- JeeSite 企业信息管理系统基础框架
- HDU 1988 Cube Stacking (数据结构-并查集)
- GITHUB使用总结