QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#386339#5809. Min Perimeterqwqer2335 216ms8748kbC++141.5kb2024-04-11 15:37:362024-04-11 15:37:36

Judging History

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

  • [2024-04-11 15:37:36]
  • 评测
  • 测评结果:5
  • 用时:216ms
  • 内存:8748kb
  • [2024-04-11 15:37:36]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ld double
#define fi first
#define se second
using namespace std;
const ll N=1e6+5,INF=1.5e9;
const ld pi=acos(-1.0l);
ll n;ld x[N],y[N];vector<pair<ld,ld>> v;
bool cmp(pair<ld,ld> u,pair<ld,ld> v){return u.fi*u.se<v.fi*v.se;}
const int D=50;
ld d[N][D+4];
ld sq(ld x){return x*x;}
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int T;cin>>T;for(int _=1;_<=T;_++){
		ll i;
		cin>>n;v.clear();
		bool b1=1;ll S=0;
		for(i=1;i<=n;i++){
			ll xx,yy;
			cin>>xx>>yy;
			x[i]=xx,y[i]=yy;
			b1&=(yy==0),S^=xx^yy;
		}
		if(b1){
			sort(x+1,x+n+1);
			ld ans=1e18;
			for(i=3;i<=n;i++) ans=min(ans,2*(x[i]-x[i-2]));
			cout<<fixed<<setprecision(15)<<ans<<'\n';
			return 0;
		}srand(19260817);
		ld t=rand()*pi*2/RAND_MAX;
		for(i=1;i<=n;i++){
			x[i]+=0.5,y[i]+=0.5;
			ld g=atan2(y[i],x[i]);
			x[i]=x[i]*cos(t+g)/cos(g);
			y[i]=y[i]*sin(t+g)/sin(g);
		}
		for(i=1;i<=n;i++){
			x[i]+=INF,y[i]+=INF;
			v.push_back({x[i],y[i]});
		}
		sort(v.begin(),v.end(),cmp);for(i=1;i<=n;i++) x[i]=v[i-1].first,y[i]=v[i-1].second;
		ld ans=1e18;
		for(i=1;i<=n;i++){
			for(int j=i+1;j<=min(n,i+D+1);j++){
				d[i][j-i]=sqrt(sq(x[i]-x[j])+sq(y[i]-y[j]));
			}
		}
		for(i=1;i<=n;i++){
			for(int j=i+1,_=min(n,i+D);j<=_;j++){
				for(int k=j+1,__=min(n,i+D);k<=__;k++){
					ans=min(ans,d[i][j-i]+d[j][k-j]+d[i][k-i]);
				}
			}
		}
		cout<<"Case #"<<_<<": "<<fixed<<setprecision(15)<<ans<<'\n';
	}
	return 0;
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 216ms
memory: 8748kb

input:

15
3
2 6
7 0
3 0
3
713 269
371 79
455 421
3
91983245 637281504
756917015 312173515
869576338 436726680
10000
14761642 78236002
9047458 47951098
5238002 27761162
476182 2523742
1428546 7571226
26190010 138805810
21904372 116092132
18094916 95902196
43332562 229660522
55237112 292754072
52380020 27761...

output:

Case #1: 17.893012279560928
Case #2: 1042.844835138164171
Case #3: 1711142102.791327238082886
Case #4: 90912.296373493416468
Case #5: 3.414213224531369
Case #6: 26.153830223199222
Case #7: 1701.012681002865520
Case #8: 2865438.191994093358517
Case #9: 2020088.337225629948080
Case #10: 1792106.037292...

result:

ok correct! (15 test cases)

Subtask #2:

score: 0
Time Limit Exceeded

Test #2:

score: 0
Time Limit Exceeded

input:

15
3
501691275 344354353
167768963 536043860
249445040 557426549
4
1000000000 0
0 0
1000000000 1000000000
0 1000000000
1000000
138925776 669369648
61257680 295150640
170762328 822763944
55483472 267329456
97736936 470914328
84041848 404928904
18463588 88960924
124429360 599523280
95066048 458045504
...

output:


result: