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;
}
题目传送门



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值