蒟蒻求调
查看原帖
蒟蒻求调
549499
Disjoint_cat楼主2023/3/29 20:16

已经调了 2h 多

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'//交互题删掉
#define FIO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define sp_el(i,n) " \n"[i==n]//空格换行
using namespace std;
void Init()
{
	
}
const int N=100005;
const double Eps=1e-11,Pi=3.141592653589793;
struct point
{
	int x,y;
	double ang;
	bool isst;
	bool operator<(const point B)
	{
		if(abs(ang-B.ang)>Eps)return ang<B.ang;
		if(y!=B.y)return y<B.y;
		return x<B.x;
	}
}p[N],s,t,mi;int mit;
double angle(point A,point B)
{
	if(B.x==A.x)
	{
		if(B.y>A.y)return Pi/2.0;
		else return Pi*1.5;
	}
	if(B.y==A.y)
	{
		if(B.x>A.x)return 0.0;
		else return Pi;
	}
	double t=atan((B.y-A.y)/(B.x-A.x));
	if(t<0.0)t+=Pi;
	if(B.y<A.y)t+=Pi;
	return t;
}
double dist(point A,point B)
{
	return hypot(A.x-B.x,A.y-B.y);
}
int n;
vector<point>ch;
double fuck_this_problem(point A,point B,point C)
{//Only for one problem, I debugged it for two hours and only for this!
//Why I have to use cross product?
//And even this got WA+RE!!
	return (B.x-A.x)*(C.y-A.y)-(B.y-A.y)*(C.x-A.x);
}
void Solve()
{
	cout<<fixed<<setprecision(15);
	cin>>n;
	for(int i=1;i<=n+2;i++)cin>>p[i].x>>p[i].y;
	p[n+1].isst=p[n+2].isst=1;
	s=p[n+1],t=p[n+2];
	mi.x=mi.y=INT_MAX;
	for(int i=1;i<=n+2;i++)
		if(p[i].y<mi.y||(p[i].y==mi.y&&p[i].x<mi.x))mi=p[i],mit=i;
	if(mit>1)swap(p[1],p[mit]);
	for(int i=2;i<=n+2;i++)
		p[i].ang=angle(p[1],p[i]);
	sort(p+2,p+n+3);
//	for(int i=1;i<=n+2;i++)cout<<p[i].x<<" "<<p[i].y<<" "<<p[i].ang<<endl;
	ch.push_back(p[1]);
	ch.push_back(p[2]);
	for(int i=3;i<=n+2;i++)
	{
		point x=p[i],y=ch.back(),z=ch.end()[-2];
		while(1)
		{
			if(fuck_this_problem(y,z,x)>=0)
			{
				ch.pop_back();
				if(ch.size()<=2)break;
				y=ch.back(),z=ch.end()[-2];
			}
			else break;
		}
		ch.push_back(x);
	}
	int st[2];int c=0;
	for(int i=0;i<ch.size();i++)
		if(ch[i].isst)st[c++]=i;//C++!
	if(c<2)return cout<<dist(s,t),void();
	double ans1=0,ans2=0;
	for(int i=st[0];i!=st[1];i=(i+1)%ch.size())
		ans1+=dist(ch[i],ch[(i+1)%ch.size()]);
	for(int i=st[1];i!=st[0];i=(i+1)%ch.size())
		ans2+=dist(ch[i],ch[(i+1)%ch.size()]);
	cout<<min(ans1,ans2);
}
void QingKong()
{

}
int main()
{
	FIO;
	int T=1;
	//cin>>T;
	Init();
	while(T--)
	//while(cin>>n&&n)
	//while(cin>>n)
	{
		Solve();
		QingKong();//多测不清空,抱灵两行泪
	}
	return 0;
}
2023/3/29 20:16
加载中...