Codeforces 185B(玄学)

97 篇文章 0 订阅

B. Mushroom Scientists
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

题解:

这题题目意思看了好久,应该是给s代表三维坐标(x,y,z)里x+y+z=s,然后给a,b,c,让你求它给出的第二个式子的最大值是多少

先讨论特殊情况当a,b,c都是0的时候,那么这个时候x,y,z应该是随便填结果都是一样的,所以满足x+y+z=s等式就行了

其他情况我是按照a,b,c的比重分配的。。猜了一发就a了,莫名其妙,貌似可以用数学公式证明

代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<stdio.h>
using namespace std;
#define ll long long

int main()
{
    double s,a,b,c,x,y,z;
    scanf("%lf%lf%lf%lf",&s,&a,&b,&c);
    if(a+b+c==0)
    {
        printf("%.18lf 0 0",s);
        return 0;
    }
    x=a*s/(a+b+c);
    y=b*s/(a+b+c);
    z=c*s/(a+b+c);
    printf("%.18lf %.18lf %.18lf",x,y,z);
    return 0;
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值