您的位置:首页 > 其它

Mushroom Scientists(Codeforce)

2017-02-16 00:04 183 查看
B. Mushroom Scientists

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) =  - ∞.

Examples

input
3
1 1 1


output
1.0 1.0 1.0


input
3
2 0 0


output
3.0 0.0 0.0


题目大意:

蘑菇王国的科学家认为传统的两点之间距离的计算公式是错误的,他们总结出了题目中所给出的计算公式用来计算两点之间的距离,即  length = xa·yb·zc 其中a+b+c<=s(当然 越大越好),也就是说a+b+c=s是固定的,且a、b、c都是大于零的,求length的最大值。

解题思路:

实际上是一道数学题。。。考的拉格朗日乘法,果断重翻大一的高数课本,拉格朗日乘法解决实际问题求极值,在高数里还是考点。。。。。手算各未知数的偏导数,代入然后写程序直接出结果。



注意事项:

①注意s或abc是0的情况下的特殊处理。

②题目最后要求误差不得高于 10 - 6,但是a、b、c最高是103,所以就算一点点小的误差也会被放大1000次幂,所以所求的数应该再精确1000倍——10 - 9,所以计算结果务必要保留到小数点后10位以上。。。。可是给的例子明明才写了小数点后1位。。。。被忽悠了。。卡到test
5和test 7上好几次。

题目代码:

#include<stdio.h>
#include<math.h>
int main()
{
double s,a,b,c,x;
while(~scanf("%lf%lf%lf%lf",&s,&a,&b,&c))
{
if(s<1 || a+b+c<1){a=0;b=0;c=0;s=1;x=1;}
else x = (a+b+c)/s;
printf("%.10f %.10f %.10f\n",a/x,b/x,c/x);
}
return 0;
}题目传送门
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: