Equation Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1873 Accepted Submission(s): 618
Problem Description
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
Author
WhereIsHeroFrom
Source
HDU女生专场公开赛——谁说女子不如男
Recommend
lcy | We have carefully selected several similar problems for you: 2668 2670 2671 2674 2673
题解:这是一道数学题, 关键在于: 从公式的化解,
由题意中的公式可化解为 log e x /x = (1+log e y)/ e*Y
然后可以得到 后面那个值为常数,则求导前面便可得到它是在【1,e】上递增,然后在【e,+无穷大】上减, 所以在e 上有唯一的一个值,其他地方都有两个值与其对应,然后分两部分二分求解
AC
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x7fffffff
#define maxn 1111
#define eps 1e-6
#define eps1 1e-10
#define pi acos(-1,0)
#define e 2.718281828459
#define mod (int)1e9+7;
int judge(double m,double y)
{
if(m/log(m)>= e*y/log(e*y))
return 1;
return 0;
}
int main()
{
double y;
while(scanf("%lf",&y)!=EOF)
{
double l=1,r=e,m;
while(r-l>eps1)
{
m=l+(r-l)/2;
if(judge(m,y))
l=m;
else
r=m;
}
double ans1=l;
l=e,r=INF;
while(r-l>eps1)
{
m=l+(r-l)/2;
if(judge(m,y))
r=m;
else
l=m;
}
double ans2=l;
if(ans2-ans1>=eps)
{
printf("%.5lf %.5lf\n",ans1,ans2);
}
else
{
printf("%.5lf\n",ans1);
}
}
return 0;
}