QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648609#4886. Best Sunrotcar07TL 1ms4352kbC++233.0kb2024-10-17 19:39:512024-10-17 19:39:52

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 19:39:52]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:4352kb
  • [2024-10-17 19:39:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
struct vec{
    ll x,y;
    vec(ll _x=0, ll _y=0):x(_x),y(_y){}
    inline vec operator + (const vec&other)const{return vec(x+other.x,y+other.y);}
    inline vec operator - (const vec&other)const{return vec(x-other.x,y-other.y);}
    inline db operator ^ (const vec&other)const{return x*other.y-y*other.x;}
};
inline db sq(db w){return w*w;}
inline db len(const vec&x){return sqrt(sq(x.x)+sq(x.y));}
inline db ang(const vec&x){return atan2(x.y,x.x);}
constexpr db eps=1e-8,pi=acos(-1);
inline db anh(const vec&x){
	db w=ang(x);
	if(w<0) w+=2*pi;
	return w;
}
inline bool chkrt(vec A,vec B,vec C){return ((B-A)^(C-A))<0;}
constexpr int maxn=305;
int n,id[maxn];
vec p[maxn];
bool f[maxn][maxn];
db dis[maxn][maxn],ag[maxn][maxn],ct[maxn][maxn];
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
vector<pii> seg;
db dp[maxn];
inline bool chk(int d,db ans){
	for(int i=1;i<=n;i++) dp[i]=-1e18;
	dp[d]=0;
	db anss=-1e18;
	for(auto x:seg){
		int u=x.fi,v=x.se;
		if(!f[u][v]) continue;
		db res=dp[u];
		res+=((p[d]-p[u])^(p[u]-p[v]))-ans*ct[u][v];
		if(v==d) anss=max(anss,res);
		else dp[v]=max(dp[v],res);
	}
	for(int i=1;i<=n;i++) anss-=ans*dis[d][i]; 
	return anss>=0;
}
inline db ff(db w){
	if(w<-pi/2) w+=2*pi;
	return w;
}
inline void solve(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>p[i].x>>p[i].y;
	sort(p+1,p+n+1,[=](const vec&x,const vec&y){return x.y==y.y?x.x<y.x:x.y<y.y;});
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
		dis[i][j]=len(p[i]-p[j]),
		ag[i][j]=ang(p[i]-p[j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			if(i==j) continue;
			seg.push_back(mp(i,j));
			vec A=p[i],B=p[j];
			vec t=B-A;swap(t.x,t.y);t.y=-t.y;
			ct[i][j]=dis[i][j];
			db w=ff(ang(t));
			for(int k=1;k<=n;k++){
				if(ff(ag[k][i])<w) ct[i][j]+=dis[i][k];
				if(ff(ag[k][j])<=w) ct[i][j]-=dis[j][k];
				if(k!=i&&k!=j&&chkrt(A,B,p[k])&&!chkrt(A,A+t,p[k])&&!chkrt(B,p[k],B+t)) 
				ct[i][j]+=min(dis[i][k],dis[j][k]);
			}
		}
	sort(seg.begin(),seg.end(),[=](const pii&x,const pii&y){return anh(p[x.se]-p[x.fi])<anh(p[y.se]-p[y.fi]);});
	db ans=0;mt19937 rnd(time(0));
	for(int i=1;i<=n;i++) id[i]=i;shuffle(id+1,id+n+1,rnd);
	for(int dd=1;dd<=n;dd++){
		int d=id[dd];
		vector<int>v;
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=0;
		for(int i=d+1;i<=n;i++) v.push_back(i),f[d][i]=f[i][d]=1;
		sort(v.begin(),v.end(),[=](int x,int y){return ag[x][d]<ag[y][d];});
		int w=n-d;for(int i=0;i<w;i++){
			vec chichi(0,0);
			for(int j=i+1;j<w;j++){
				int a=v[i],b=v[j];
				if((chichi^(p[b]-p[a]))>=0){
					chichi=p[b]-p[a];
					f[a][b]=f[b][a]=1;
				}
			}
		}
		if(!chk(d,ans)) continue;
		db l=ans,r=2e6;
		while(fabs(r-l)>eps){
			db mid=(l+r)/2;
			if(chk(d,mid)) l=ans=mid,l+=eps;
			else r=mid-eps;
		}
	}
	cout<<fixed<<setprecision(10)<<ans/2<<'\n';
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--) solve();
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4352kb

input:

4
3
-1 -1
1 -1
0 1
4
0 0
10 0
0 10
8 1
5
2 0
-2 0
1 1
-1 1
0 3
8
4 4
-4 4
4 -4
-4 -4
5 6
-6 5
-5 -6
6 -5

output:

0.3090169919
1.2368614178
0.2711375414
1.5631002078

result:

ok 4 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

10000
3
702262 828158
-350821 -420883
-466450 13507
3
28647 -193498
126436 -864937
-287798 738936
3
270358 -269567
745815 -485408
834083 677952
3
-2036 -403634
742978 -263774
975937 -609237
3
584248 -472620
482016 -356760
284902 903881
3
-292004 504925
-935756 373793
-781101 -434659
3
-858513 684433...

output:

85789.0873983494
18268.5193616644
102489.9883902566
66685.7544280744
18674.6579374054
106468.9651319629
14427.0246510652
29966.2453025415
143547.7510835845
13097.1756881260
162410.1683169778
72070.9324178685
29369.9926278729
52867.2944310910
90314.3083467443
99775.9271965566
144449.7053083573
64406....

result: