记录编号 |
86120 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[UVa 10341] 解方程 |
最终得分 |
100 |
用户昵称 |
cstdio |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.126 s |
提交时间 |
2014-01-20 21:59:09 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<iomanip>
#include<queue>
#include<set>
#include<map>
using namespace std;
const double eps=1e-10;
double p,q,r,s,t,u;
double F(double x){
return p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
}
double binary_solve(double (*f)(double),double x,double y,double type){//f是函数,在区间[x,y]内,type是类型(1是增0是减)
if(y-x<eps) return (x+y)/2;
double mid=(x+y)/2;
if(f(mid)>0){
if(type) return binary_solve(f,x,mid,type);
else return binary_solve(f,mid,y,type);
}
else{
if(type) return binary_solve(f,mid,y,type);
else return binary_solve(f,x,mid,type);
}
}
bool work(void){
if(scanf("%lf%lf%lf%lf%lf%lf",&p,&q,&r,&s,&t,&u)==EOF) return false;
double f0=F(0),f1=F(1);
if(f1>eps||f0<-eps) printf("No solution\n");
else printf("%.4lf\n",binary_solve(F,0,1,0));
return true;
}
int main(){
freopen("solveit.in","r",stdin);
freopen("solveit.out","w",stdout);
while(work());
return 0;
}