D - Equation Again

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

二分就好了,只有1的时候才只有一个答案,其他都是2个,注意输出5位小数我是个傻子

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h> 
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<map>
#define for(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e12+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
db ans;
int judge(db mid)
{
    db cas=log(mid)/mid;
    if(cas==ans) return 0;
    else if(cas<ans) return -1;
    else if(cas>ans) return 1;
}
int main()
{
    db x,y;
    while(~sf("%lf",&y))
    {
        if(y==1)
        {
            pf("%.5lf\n",e);continue;
        }
        ans=(1+log(y))/(e*y);
        db left=1,right=e,mid;
        while(right-left>0.00000001)
        {
            mid=(left+right)/2;
            if(judge(mid)==0) break;
            else if(judge(mid)==1) right=mid;
            else left=mid;
        }
        pf("%.5lf ",mid);
        left=e,right=DBL_MAX;
        while(right-left>0.00000001)
        {
            mid=(left+right)/2;
            if(judge(mid)==0) break;
            else if(judge(mid)==1) left=mid;
            else right=mid;
        }
        pf("%.5lf\n",mid);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/wzl19981116/p/9382199.html