UVA10341 二分枚举解方程

版权声明:本文为博主原创文章,未经博主允许也可以转载。 https://blog.csdn.net/FrankAx/article/details/74251857
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <math.h>
#define INF  1e-14
#define MIN 1e-14         //精度
using namespace std;
double p,q,r,s,t,u;
double fun(double x){
  return p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
}
int main()
{
		while(cin>>p>>q>>r>>s>>t>>u){      
			double l = 0;
		double r = 1;
		double mid;
	 	if(fun(0)<0 || fun(1)>0){
	 		cout<<"No solution"<<endl;
	 	}else{
	 		while((r-l)>INF){		
			  mid = l+(r-l)/2.0;
			  double temp = fun(mid);
			 if(temp<0){
				r = mid;
			}else{
				l = mid;	
			}

		}
		printf("%.4lf\n",mid);
	 	}
		}
		
	return 0;
}

展开阅读全文

没有更多推荐了,返回首页