Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- double distance_checker(double D, double v,double T, double w);
- int main() {
- FILE*fin = fopen("input.txt","r");
- FILE*fout = fopen("output.txt","w");
- double D, T , v1 , v2, w1, w2, maximum_distance;
- double distance[4];
- fscanf(fin,"%lf%lf%lf%lf%lf%lf", &D, &T, &v1, &v2, &w1, &w2);
- distance[0] = distance_checker(D, v1, T, w1);
- distance[1] = distance_checker(D, v2, T, w1);
- distance[2] = distance_checker(D, v1, T, w2);
- distance[3] = distance_checker(D, v2, T, w2);
- maximum_distance = 0;
- for (int i = 0; i < 4; ++i) {
- if (distance[i] >= maximum_distance){
- maximum_distance = distance[i];
- }
- if (maximum_distance > D){
- maximum_distance = D;
- }
- }
- fprintf(fout,"%lf",maximum_distance);
- fclose(fin);
- fclose(fout);
- return 0;
- }
- double distance_checker(double D, double v,double T, double w) {
- if (v-w == 0){
- return 0;
- }
- double distance = (D - w * T) * v / (v - w);
- if (((D - w * T) / (v - w)) > T){
- return T*v;
- }
- if (distance>D){
- return D;
- }
- return distance;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement