There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location and moves at a rate of meters per jump. The second kangaroo starts at location and moves at a rate of meters per jump. Given the starting locations and movement rates for each kangaroo, can you determine if they'll ever land at the same location at the same time?
Input Format
A single line of four space-separated integers denoting the respective values of , , , and .
Constraints
- 0<= x1 < x2 <= 10000
- 1 <= x1 <= 10000
- 1<= v2 <= 10000
Output Format
Print YES
if they can land on the same location at the same time; otherwise, print NO
.
MY EXPLANATION:
This is a simple high school maths problem like 2 trains start at different location,given their velocity can you find whether they will ever meet or not?
Let's name the kangaroo's as K1 and K2 and given K2 starts ahead of K1 (i.e. x2 > x1).
Now, they will meet only when distance traveled by K1 is equal to the sum of distance traveled by K2 and their initial separation(i.e. (x1-x2) + distance(K2) ). This is visualized below.
let say they meet after time T then the condition will be
v1*T = (x2 - x1) + v2*T
In other word, they will meet if
T = ( x2 - x1 ) % ( v1 - v2 ) is equal to 0 ( zero)
Now try to write your own code keeping these things in mind.
If you don't succeed than take a look at my solution.
Input Format
A single line of four space-separated integers denoting the respective values of , , , and .
Constraints
- 0<= x1 < x2 <= 10000
- 1 <= x1 <= 10000
- 1<= v2 <= 10000
Output Format
Print
YES
if they can land on the same location at the same time; otherwise, print NO
.
MY EXPLANATION:
This is a simple high school maths problem like 2 trains start at different location,given their velocity can you find whether they will ever meet or not?
Now, they will meet only when distance traveled by K1 is equal to the sum of distance traveled by K2 and their initial separation(i.e. (x1-x2) + distance(K2) ). This is visualized below.
v1*T = (x2 - x1) + v2*T
In other word, they will meet if
T = ( x2 - x1 ) % ( v1 - v2 ) is equal to 0 ( zero)
Now try to write your own code keeping these things in mind.
#include <iostream>
using namespace std;
int main(){
int x1, x2, v1, v2; /* Initializing variables */
cin >> x1 >> v1 >> x2 >> v2; /* assigining values to the variables */
if( v1>v2 && (x2-x1)%(v1-v2)==0 )cout<<"YES"; /* if this is the case than they will meet , so print YES */
else cout<<"NO"; /* In any other case they wont meet */
return 0;
}
Question Source: hackerrank.com
Hello..
ReplyDeleteOne of the most popular reasons as to why quick property sale services have become so popular in recent years comes from how this type of sale is one that can be handled on a variety of different types of properties. There are a number of properties that can be handled through the use of a quick property sale. This is a type of sale that can be used to help you with getting your property sold off quickly.One of the most valuable processes that you can use with regards to avoiding repossession is to look into getting into a quick property sale. This is a type of sale that can be used to help you with getting your property sold off quickly.property for sale
Nice. This was a nice explanation. Thanx.
ReplyDeleteIf this week’s PGA Championship is anything like the other majors this season, it will be one of the most-watched PGA Championships in recent memory. Much of that can be attributed to the return of Tiger Woods.
ReplyDeleteWhether it’s Woods, Rory McIlroy, Jordan Spieth or another reason that has you tuning in for the event, there will be no shortage on places your can view it. As far as online streaming goes, there will be featured group coverage provided by the event and Turner and CBS, which owns the rights to broadcast the tournament. (Look for Woods to be in one of those featured groups. He has been most of the season.)
Check out the schedule below for all your streaming needs, which can be found on PGA.com and the PGA Championship mobile app. (All times ET.)
Featured Group No. 1 (a.m. and p.m. groups)
Thurs / Fri: 8:30 a.m. – 7 p.m.
Sat / Sun: 11 a.m. – 7 p.m.
Featured Group No. 2 (a.m. and p.m. groups)
Thurs / Fri: 9:30 a.m. – 7 p.m.
Sat / Sun: 11 a.m. – 7 p.m.
Featured Holes: 16, 17, & 18
Thurs/Fri: 2 p.m. – 8 p.m.
Sat/Sun: 11 a.m. – 7 p.m.
TNT Simulcast
Thurs/Fri: 2 – 8 p.m.
Sat/Sun: 11 a.m. – 2 p.m.
CBS Simulcast
Sat / Sun: 2 p.m. – 7 p.m.
PGA Championship
PGA Championship Live
PGA Championship Live Stream
PGA Championship 2018
PGA Championship Golf
PGA Championship
PGA Championship Live
PGA Championship 2018
PGA Championship Golf
2018 PGA Championship
This comment has been removed by a blog administrator.
ReplyDeleteCanelo vs GGG
ReplyDeleteCanelo vs GGG Live
Canelo vs GGG Live Stream
Canelo vs GGG 2
Canelo vs GGG 2 Live Stream
GGG vs Canelo
GGG vs Canelo Live
GGG vs Canelo 2
GGG vs Canelo 2 Live
Canelo vs GGG Fight
Canelo vs GGG Boxing
Canelo GGG
Canelo GGG Live
Canelo GGG Fight
Canelo vs Golovkin
Canelo vs Golovkin Live
Canelo vs Golovkin Live Stream
Canelo vs Golovkin 2
Canelo vs Golovkin 2 Live
Golovkin vs Canelo
Golovkin vs Canelo Live
Golovkin vs Canelo 2
Golovkin vs Canelo 2 Live
Canelo vs Golovkin Fight
Canelo vs Golovkin Boxing
Canelo Golovkin
Canelo Golovkin Live
Joshua vs Povetkin
ReplyDeleteJoshua vs Povetkin Live
Joshua vs Povetkin Live Stream
Joshua v Povetkin
Joshua v Povetkin Live
Povetkin vs Joshua
Povetkin vs Joshua Live
Povetkin v Joshua
Joshua vs Povetkin
Joshua vs Povetkin Live
Joshua vs Povetkin Fight
Joshua v Povetkin
Povetkin vs Joshua
Total Sportek
ReplyDeleteTotal Sportek Live
Total Sportek Live Stream
Total Sportek Live Streaming
Total Sportek Live Free
Total Sportek Live Online
Watch Total Sportek
Total Sportek Live Scores
TotalSportek
TotalSportek Live