```
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
const double eps=1e-3;
const int MAXN=5005;
int n;
double x[MAXN],y[MAXN],k[MAXN],b[MAXN];
double ans;
bool check(double x)
{
double L=-2e9,R=2e9;
for(int i=2;i<=n;i++)
{
if(k[i]<0) L=max(L,((x-b[i])/k[i]));
else if(k[i]>0) R=min(R,((x-b[i])/k[i]));
else if(x<b[i]) return false;
}
return L<=R;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>x[i]>>y[i];
for(int i=2;i<=n;i++)
{
k[i]=(y[i]-y[i-1])/(x[i]-x[i-1]);
b[i]=y[i]-k[i]*x[i];
}
double l=0,r=1e9;
while(eps<=r-l)
{
double mid=(l+r)/2;
if(check(mid)) r=mid,ans=mid;
else l=mid;
}
printf("%.2lf",ans);
return 0;
}
```
你看看这个代码
by MilchstraBe @ 2023-08-08 21:13:50
@[Pandaburnincense](/user/1060433) 题解?
by wzh041500 @ 2023-08-09 16:20:07
我写的题解
by MilchstraBe @ 2023-08-09 19:28:58
```cpp
#include<bits/stdc++.h>
using namespace std;
struct node{
double x,y;
}sh[5009];
int n;
bool pan(int yy)
{
double l=0,r=2000000000;
for(int i=1;i<n;i++)
{
if(sh[i].y==sh[i+1].y)
{
if(yy<sh[i].y)return 0;
}
else
{
if(sh[i].y>sh[i+1].y)
{
l=max(l,((sh[i+1].x-sh[i].x)*(yy-sh[i].y)/(sh[i+1].y-sh[i].y)+sh[i].x));
if(l>r)return 0;
}
else
{
r=min(r,((sh[i+1].x-sh[i].x)*(yy-sh[i].y)/(sh[i+1].y-sh[i].y)+sh[i].x));
if(l>r)return 0;
}
}
// cout<<l<<" "<<r<<" ";
}
cout<<l<<" "<<r<<' ';
if(l>r)return 0;
return 1;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>sh[i].x>>sh[i].y;
}
double l=0,r=1000000,mid,ans=-1;
while(l<=r)
{
mid=(l+r)/2;
if(pan(mid))
{
r=mid-0.0001;
ans=mid;
}
else
{
l=mid+0.0001;
}
}
cout<<ans;
return 0;
}
```
改了一下 。。。。。。。。。。。。。。。。0分。。。。。。。。。。。。。。。。。。
啊~~~~~~
by wzh041500 @ 2023-08-09 19:38:30
喵也无语...........
by MilchstraBe @ 2023-08-09 20:20:43
喵觉得是输出问题。
by MilchstraBe @ 2023-08-09 20:23:08
函数pan输入值没用double,用了int(第七行)
肥肠低级的错误
。
。
是我太弱了~~~
by wzh041500 @ 2023-08-09 20:57:41
警示后人
此篇终。。。。。
by wzh041500 @ 2023-08-09 20:59:23
@[Pandaburnincense](/user/1060433)
头像不错
by wzh041500 @ 2023-08-09 21:00:45
呵呵
by MilchstraBe @ 2023-08-10 15:43:10