Created
February 13, 2014 22:04
-
-
Save py4/8984838 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <climits> | |
using namespace std; | |
double truncate(long double number, int n) | |
{ | |
return (int)(number*pow(10,n)) / (float)pow(10,n); | |
} | |
long double get_consumption(double a, double b, double c, double d, double v) | |
{ | |
return a*pow(v,3) + b*pow(v,2) + c*v + d; | |
} | |
double max_velocity(double a,double b, double c, double d, double start, double end,double max_consumption) | |
{ | |
/*cout << "start: " << start << endl; | |
cout << "end: " << end << endl;*/ | |
double temp; | |
double new_v = (start + end) / 2; | |
if((temp = truncate(new_v,3)) == truncate(start,3) or temp == truncate(end,3)) | |
{ | |
// cout << "temp: " << temp << endl; | |
// cout << "start: " << truncate(start,3) << endl; | |
// cout << "end: " << truncate(end,3) << endl; | |
return truncate(temp,2); | |
} | |
else | |
{ | |
double start_consumption = get_consumption(a,b,c,d,start) - max_consumption; | |
double new_consumption = get_consumption(a,b,c,d,new_v) - max_consumption; | |
double end_consumption = get_consumption(a,b,c,d,end) - max_consumption; | |
if(start_consumption == 0) | |
return start; | |
if(new_consumption == 0) | |
return new_v; | |
if(end_consumption == 0) | |
return end; | |
if((start_consumption > 0 and new_consumption < 0) or (start_consumption < 0 and new_consumption > 0)) | |
//cout << "fuck:" << endl; | |
//cout << abs(start_consumption - end_consumption) << endl; | |
//if(abs(start_consumption - end_consumption) < pow(10,-6)) | |
return max_velocity(a,b,c,d,start,new_v,max_consumption); | |
else | |
//if((new_consumption > 0 and end_consumption < 0) or (new_consumption < 0 and end_consumption > 0)) | |
return max_velocity(a,b,c,d,new_v,end,max_consumption); | |
/*else | |
return max_velocity(a,b,c,d,start,new_v,max_consumption);*/ | |
} | |
} | |
int main() | |
{ | |
double a,b,c,d,m,t; | |
while(cin >> a >> b >> c >> d >> m >> t) | |
cout << max_velocity(a,b,c,d,0,pow(10,6),t/m) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment