zoukankan      html  css  js  c++  java
  • codeforces624A

    Save Luke

     CodeForces - 624A 

    Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other with speed v1and v2, respectively. Luke has width d and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.

    Input

    The first line of the input contains four integers dLv1v2 (1 ≤ d, L, v1, v2 ≤ 10 000, d < L) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.

    Output

    Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

    Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

    Examples

    Input
    2 6 2 2
    Output
    1.00000000000000000000
    Input
    1 9 1 2
    Output
    2.66666666666666650000

    Note

    In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.

    In the second sample he needs to occupy the position . In this case both presses move to his edges at the same time.

    sol:小学奥数中的相遇问题。。。

    #include <bits/stdc++.h>
    using namespace std;
    typedef int ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0'); return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    double d,L,V1,V2; 
    int main()
    {
        scanf("%lf%lf%lf%lf",&d,&L,&V1,&V2);
        printf("%.15lf
    ",(double)(L-d)/(V1+V2));
        return 0;
    }
    /*
    input
    2 6 2 2
    output
    1.00000000000000000000
    
    input
    1 9 1 2
    output
    2.66666666666666650000
    */
    View Code
  • 相关阅读:
    MongoDB zip 包安装注意事项及过程
    20个免费的React Admin仪表板模板
    React常用的5个UI框架
    create-react-app my-app出错
    查看Vue,React等框架的排名以及编程语言的排名
    flex流动布局中的单个子元素位置如何自定义
    小程序跳转页面后,动态刷新跳转页面
    table表格动态合并
    Windows 10 提权漏洞复现及武器化利用
    ISO:Fedora/Centos-6/7-LiveCD 利用iso文件 本地硬盘安装:方式1:Grub4Dos partnew模拟
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10585140.html
Copyright © 2011-2022 走看看