|
|
вернуться в форумPLEASE HELP WA10 (something wrong with accuracy) #include<iostream> #include<iomanip> #include<cmath> int a1,b1,a2,b2; double func(double x); int main() { using std::cin; using std::cout; using std::endl; cin >> a1 >> b1 >> a2 >> b2; double delta = 1e-4; double head = 1e-4; double tail = 1000000+head; while(1) { double mid = 0.5*(head + tail); double cur = func(mid); double up = func(mid+delta); double down = func(mid - delta); if((cur-up)*(cur-down)>=0) { cout.setf(std::ios::fixed|std::ios::showpoint); cout.precision(9); cout << cur << endl; return 0; }else { if(up>=cur) { head = mid + delta; } else { tail = mid - delta; } } } } double func(double x) { return sqrt((a1+b1*x)*(a1+b1*x)/(1 + x*x) + (a2+b2*x)*(a2+b2*x) / (1 + x*x)); } Re: PLEASE HELP WA10 (something wrong with accuracy) Послано Anton 24 окт 2008 16:09 try lond double for func & x, and long long for a1,a2,b1,b2. i don't sure, but it must help... |
|
|