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
  • 相关阅读:
    分析WordPress数据表之用户表(功能篇)
    Android.mk简介:
    win10 mars xlog编译
    sudo apt-get install libstdc++6
    WebRTC 入门教程(二)| WebRTC信令控制与STUN/TURN服务器搭建
    Mars Android 接入指南
    Mars Sample 使用说明
    RxJava2 方法总结
    mqtt client api: 阻塞API
    idea使用git进行项目管理
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10585140.html
Copyright © 2011-2022 走看看