https://ac.nowcoder.com/acm/contest/3006/B
The meaning of problems
Because beef clan often away matches, so a lot of the country to establish training bases, each base has a coordinate (the X-, the y-) .
This weekend, Taurus team have to go out of the game, each match point game in x -axis. Taurus team for the convenience of the game, looking for a training base to reach the maximum and minimum distances as a place to race.
Code
Bipartite
How to determine the current maximum distance is not a feasible solution, you can find the current maximum determined distance range for each point whether there is an intersection of the x (circle equation)
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
struct node
{
int x,y;
}point[maxn];
int n;
int check(double r);
int main()
{
int i;
double l=0,r=0x7fffffff,mid,ans;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d%d",&point[i].x,&point[i].y);
while(r-l>1e-8)
{
mid=(l+r)/2;
if(check(mid)) ans=mid,r=mid;
else l=mid;
}
printf("%lf",ans);
system("pause");
return 0;
}
int check(double R)
{
double l=-(0x7fffffff),r=0x7fffffff,gap;
for(int i=1;i<=n;i++)
{
if(R<fabs(point[i].y))
return 0;
gap=sqrt(R*R-point[i].y*point[i].y);
l=max(l,point[i].x-gap);
r=min(r,point[i].x+gap);
}
return r>=l;
}
Thirds
template.
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
struct node
{
int x,y;
}point[maxn];
int n;
double check(double r);
int main()
{
int i;
double l=-(0x7fffffff),r=0x7fffffff,mid,mmid;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d%d",&point[i].x,&point[i].y);
for(i=0;i<100;i++)
{
mid=(r+l)/2;
mmid=(r+mid)/2;
if(check(mid)>check(mmid))
l=mid;
else
r=mmid;
}
printf("%lf",check(mid));
system("pause");
return 0;
}
double check(double R)
{
double maxn=0;
for(int i=1;i<=n;i++)
maxn=max(maxn,sqrt(point[i].y*point[i].y+(point[i].x-R)*(point[i].x-R)));
return maxn;
}