Equation Again

来源:互联网 发布:耐高温密封条 淘宝 编辑:程序博客网 时间:2024/06/14 13:01
This problem’s author is too lazy to write the problem description, so he only give you a equation like X(eY) == (eY)x, and the value of Y, your task is calculate the value of X.
Note : here e is the Natural logarithm.
Input
Each line will contain one number Y(Y >= 1). Process to end of file.
Output
For each case, output X on one line, accurate to five decimal places, if there are many answers, output them in increasing order, if there is no answer, just output “Happy to Women’s day!”.
Sample Input
1
Sample Output
2.71828
#include <iostream>#include <cmath>#include <cstdio>using namespace std;const double e=2.718281828459;const double eps=1e-7;int main(){    double y;    while(cin>>y)    {        double ans=log(e*y)/(e*y);        double left=0,right=e;        while(right-left>eps)        {            double mid=(left+right)/2;            double temp=log(mid)/mid;             if(temp>=ans)right=mid-eps;             else left=mid;        }        if(fabs(y-1)>eps)            printf("%.5f %.5f\n",right,e*y);        else            printf("%.5f\n",e*y);    }    return 0;}
注意浮点型的二分。
原创粉丝点击