题目描述
blablabla
样例
blablabla
算法1
(二分) $O(n^2)$
blablabla
时间复杂度分析:blablabla
C++ 代码
blablabla
C++ 代码
blablabla
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
double n;
double l ,r;
int main()
{
cin >> n;
int flag =1;
if(n<0)
{
n =n-1;
l =0, r= n ;
flag = -1;
}
else
{
l =0,r=n;
}
while(r -l > 1e-8)
{
double mid = (r+l)/2;
if(midmid*mid>n)r=mid;
else l = mid;
}
printf(“%lf”,flag * l);
return 0;
}