There are two monkeys on an x-axis ready to jump in the positive direction (i.e, toward positive infinity).The first monkey starts at location x1 and moves at a rate of v1 meters per jump. The second monkey starts at location x2 and moves at a rate of v2 meters per jump. Given the starting locations and movement rates for each monkey, can you determine if they'll ever land at the same location at the same time?
#include<stdio.h>
int main()
{int x1,x2,v1,v2;
scanf("%d %d %d %d",&x1,&v1,&x2,&v2);
int m=x1,n=x2;
if (v2>v1){printf("NO");}
else {for (int i=0;i<10000;i++){m=m+v1;
n=n+v2;
if(m==n){printf("YES"); break;}}
if(m!=n)printf("NO");
}
return 0;
}
Comments
Post a Comment