• Codeforces Round #620 (Div. 2) A. Two Rabbits


    Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other.

    He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits can be represented as integer coordinates on a horizontal line. The taller rabbit is currently on position xx , and the shorter rabbit is currently on position yy (x<yx<y ). Every second, each rabbit hops to another position. The taller rabbit hops to the positive direction by aa , and the shorter rabbit hops to the negative direction by bb .

    For example, let's say x=0x=0 , y=10y=10 , a=2a=2 , and b=3b=3 . At the 11 -st second, each rabbit will be at position 22 and 77 . At the 22 -nd second, both rabbits will be at position 44 .

    Gildong is now wondering: Will the two rabbits be at the same position at the same moment? If so, how long will it take? Let's find a moment in time (in seconds) after which the rabbits will be at the same point.

    Input

    Each test contains one or more test cases. The first line contains the number of test cases tt (1t10001≤t≤1000 ).

    Each test case contains exactly one line. The line consists of four integers xx , yy , aa , bb (0x<y1090≤x<y≤109 , 1a,b1091≤a,b≤109 ) — the current position of the taller rabbit, the current position of the shorter rabbit, the hopping distance of the taller rabbit, and the hopping distance of the shorter rabbit, respectively.

    Output

    For each test case, print the single integer: number of seconds the two rabbits will take to be at the same position.

    If the two rabbits will never be at the same position simultaneously, print 1−1 .

    Example


    Input
    5
    0 10 2 3
    0 10 3 3
    900000000 1000000000 1 9999999
    1 2 1 1
    1 3 1 1
    
    Output
    2
    -1
    10
    -1
    1

    小学生水题,就是路程问题,不能整除的话输出-1。
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            long long a,b,x,y;
            cin>>x>>y>>a>>b;
            long long ans=0;
            if((y-x)%(a+b)==0)
            {
                ans=(y-x)/(a+b);
            }
            else ans=-1;
            cout<<ans<<endl;
        }
        return 0;
    }


  • 相关阅读:
    SQL 行转列查询汇总
    c#中的委托是什么,事件是不是一种委托
    添加动画(两种)
    Follow 在地图中使地图和人物一起运动
    动作加速度Speed
    动作回调函数 (CallFunc,CallFuncN,CCCallFuncND)
    精灵沿着正方形路线运动暂停2秒后然后再将自己放大4倍
    CardinalSpline样条曲线(沿着正方形路线走)
    cocos2dx 3.2 Scale9Sprite点九图
    Label(标签)
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12315916.html
Copyright © 2020-2023  润新知