View Code of Problem 104

#include<bits/stdc++.h>
using namespace std;
int main() {
	double n,v1,v2,t;
	while(cin>>n>>v1>>v2>>t) {
		n*=1000;
		if(v1<0) {
			if(v2<0) {
				if(abs(v1)>abs(v2))
					printf("NO\n");
				else {
					double time=n/((abs(v2)-abs(v1)));
					if(time<=t)
						printf("%.2lf\n",time);
					else
						printf("NO\n");
				}
			} else {
				printf("NO\n");
			}

		} else {
			if(v2<0) {
				double time=n/((abs(v2)+abs(v1)));
				if(time<=t)
						printf("%.2lf\n",time);
					else
						printf("NO\n");
			} else {
				if(abs(v1)<abs(v2))
					printf("NO\n");
				else {
					double time=n/((abs(v1)-abs(v2)));
					if(time<=t)
						printf("%.2lf\n",time);
					else
						printf("NO\n");
				}
			}
		}
	}

}

Double click to view unformatted code.


Back to problem 104