UVa-10341

来源:互联网 发布:简易html5小游戏源码 编辑:程序博客网 时间:2024/06/16 04:00

题意:解方程

p*e-x q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0
        where 0 <= x <= 1.(0 <= p,r <= 20 and -20 <= q,s,t <= 0

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=493&problem=1282

观察可得 求导可得此函数是递减函数 判断是否有解即 f(0) * f(1) <= 0

在此还要懂得运用 三角函数 ,还有求e^(-x) ,要用到exp函数求解 e^(-x) = exp(-x);

三角函数sin(x) 中x指的经过角度变化的弧度

解决此题用二分求解

#include<stdio.h>#include<math.h>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 ;}void find(double x,double y){    double mid;    while(y - x > 0.000000001)    {        mid =( x + y ) / 2 ;        double t = f(mid) ;        if(t < 0) y = mid;        else x = mid ;    }    printf("%.4lf\n",mid);}int main(){    while(scanf("%lf%lf%lf%lf%lf%lf",&p,&q,&r,&s,&t,&u)!=EOF)    {        if(f(0) * f(1) > 0) printf("No solution\n");        else        {            find(0.0,1.0);        }    }}



0 0