UVA 10341 Solve It(2分)

849 ワード

タイトル:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19047
コード:
#include<stdio.h>
#include<string.h>
#include<math.h>
#define F(x) p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u

using namespace std;

int main()
{
    int p,q,r,s,t,u;

    while(~scanf("%d%d%d%d%d%d",&p,&q,&r,&s,&t,&u))
    {
        double f0=F(0),f1=F(1);
        if(f0<0||f1>0)
        {
            printf("No solution
"); } else { double x=0,y=1,ans; for(int i=0;i<=100;i++) { ans=x+(y-x)/2; if(F(ans)>0) x=ans; else y=ans; } printf("%.4lf
",ans); } } }