Mushroom Scientists
2015-08-27 11:56
351 查看
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 equals xa·yb·zc.
To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, 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.
Input
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.
Output
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 than 10 - 6. We think that ln(0) = - ∞.
Sample test(s)
input
3
1 1 1
output
1.0 1.0 1.0
input
3
2 0 0
output
3.0 0.0 0.0
说了半天就是一个不等式,直接把x拆成a个x/a,把y拆成b个y/b,把z拆成c个z/c,直接平均不等式,左面是要求的结果和常数,右边是常数,取等条件就是结果。
注意保留的位数,这题要保留到十位,送了2发。
To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, 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.
Input
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.
Output
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 than 10 - 6. We think that ln(0) = - ∞.
Sample test(s)
input
3
1 1 1
output
1.0 1.0 1.0
input
3
2 0 0
output
3.0 0.0 0.0
说了半天就是一个不等式,直接把x拆成a个x/a,把y拆成b个y/b,把z拆成c个z/c,直接平均不等式,左面是要求的结果和常数,右边是常数,取等条件就是结果。
注意保留的位数,这题要保留到十位,送了2发。
#include<cstdio> #include<cstring> #include<iostream> #include<queue> #include<vector> #include<algorithm> #include<string> #include<cmath> #include<set> #include<map> #include<vector> using namespace std; typedef long long ll; const int inf = 0x3f3f3f3f; const int maxn = 1005; int main() { int i, j, m, n, ans, t, s, x, y, z; cin >> s; double a, b, c; cin >> x >> y >> z; if (x == 0 && y == 0 && z == 0) { a = b = c = s / 3; cout << a << " " << b << " " << c << endl; } else { int sum = x + y + z; a = s*x*1.0 / sum; b = s*y*1.0 / sum; c = s*z*1.0 / sum; printf("%.10lf %.10lf %.10lf\n", a, b, c); } return 0; }
相关文章推荐
- hdu 4268 Alice and Bob(lower_bound+贪心)
- Java____java.lang.object
- javascript实现图片延迟加载方法汇总(三种方法)
- Javascript 页面跳转
- Markdown常用语法简介
- jQueryMobile的组件——页面(page)
- 我自己整理的一份reset.less 以作记录
- host文件
- Android中Button控件Buttons in button bars should be borderless;警告信息
- unity之ugui
- 用maven编译spark1.4
- 一个比较完整的Inno Setup 安装脚本
- [C++] Most Vexing Parse
- 【这里有别人的经验,也有好玩的发现】
- C-5 猜数字游戏
- LoadRunner11学习记录二
- Jquery DIV滚动至浏览器顶部位置固定
- GBRank的问题列表
- Mongodb的安装和简单的使用
- 解决URL二次编码的问题