Mushroom Scientists(Codeforce)

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, zx + 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 abc (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;
}
題目傳送門



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章