QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#386324#5809. Min PerimeterKonvex0 14147ms84084kbC++142.5kb2024-04-11 15:31:372024-04-11 15:31:38

Judging History

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

  • [2024-04-11 15:31:38]
  • 评测
  • 测评结果:0
  • 用时:14147ms
  • 内存:84084kb
  • [2024-04-11 15:31:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 1000100
struct vec{
	int x,y;
};
int n;
vec a[N];
double dist(vec a,vec b){
	double x=a.x-b.x,y=a.y-b.y;
	return sqrt(x*x+y*y);
}
double calc(vec a,vec b,vec c){
	return dist(a,b)+dist(b,c)+dist(c,a);
}
namespace h{
	struct node{
		int xid,yid,nxt;
	}d[N<<1];
	int head[N],tot=1;
	vector<int> vis;
	vector<int> dt[N];
	void clear(){
		for(int id:vis){
			int u=head[id];head[id]=0;
			while(u){
				dt[u].clear();dt[u].shrink_to_fit();
				int v=d[u].nxt;
				d[u].xid=d[u].yid=d[u].nxt=0;
				u=v;
			}
		}
		vis.clear();tot=1;
	}
	int zget(double x){
		if(x>=0)return (int)x;
		else return -(int)(-x)-1;
	}
	int getnode(int xid,int yid){
		long long hsh=((1LL*xid*1145141919LL+yid)%N+N)%N;
		int u=head[hsh];
		while(u){
			if(d[u].xid==xid&&d[u].yid==yid){
				return u;
			}
			u=d[u].nxt;
		}
		return -1;
	}
	void insert(int idx,double C){
		vec z=a[idx];
		int xid=zget(z.x/C),yid=zget(z.y/C);
		long long hsh=((1LL*xid*1145141919LL+yid)%N+N)%N;
		int u=getnode(xid,yid);
		if(u==-1){
			int u=tot++;d[u].xid=xid;d[u].yid=yid;d[u].nxt=head[hsh];
			if(!d[u].nxt)vis.push_back(hsh);
			head[hsh]=u;dt[u].push_back(idx);
		}else{
			dt[u].push_back(idx);
		}
	}
};
void build(double C,int m){
	h::clear();
	for(int i=1;i<=m;i++){
		h::insert(i,C);
	}
}
int dir[9][2]={
	{-1,-1},{-1,0},{-1,1},{0,-1},{0,0},{0,1},{1,-1},{1,0},{1,1}
};
vector<int> tmp;
int work(int tid){
	//freopen("triangle.in","r",stdin);
	//freopen("triangle.out","w",stdout);
	h::clear();tmp.clear();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&(a[i].x),&(a[i].y));
	random_shuffle(a+1,a+n+1);
	double ans=calc(a[1],a[2],a[3]);
	build(ans/2,3);
	//printf("init ans=%lf\n",ans);
	for(int i=4;i<=n;i++){
		if(ans<1e-6)break;
		int xid=h::zget(a[i].x/(ans/2)),yid=h::zget(a[i].y/(ans/2));
		tmp.clear();
		for(int j=0;j<9;j++){
			int nx=xid+dir[j][0],ny=yid+dir[j][1];
			int id=h::getnode(nx,ny);if(id==-1)continue;
			for(int idx:h::dt[id]){
				if(dist(a[i],a[idx])<ans/2)tmp.push_back(idx);
			}
		}
		double tans=ans;
		for(int j=0;j<tmp.size();j++){
			for(int k=j+1;k<tmp.size();k++){
				tans=min(tans,calc(a[i],a[tmp[j]],a[tmp[k]]));
			}
		}
		if(tans+1e-9<ans){
			//printf("ans=%lf,tans=%lf\n",ans,tans);
			ans=tans;
			build(ans/2,i);
		}else{
			h::insert(i,ans/2);
		}
	}
	printf("Case #%d: %lf\n",ans);
	return 0;
}
int main(){
	int t;scanf("%d",&t);
	for(int i=1;i<=t;i++)work(i);
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 45ms
memory: 31856kb

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 #0: 17.893012
Case #0: 1042.844835
Case #0: 1711142102.791327
Case #0: 90912.296374
Case #-1338063856: 3.414214
Case #0: 26.153830
Case #0: 1701.012681
Case #0: 2865438.191994
Case #0: 2020088.337226
Case #0: 1792106.037292
Case #0: 2019352.542910
Case #0: 2530195.728018
Case #0: 930517.779631
...

result:

wrong output format Expected '#1:' but found '#0:' (test case 1)

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 14147ms
memory: 84084kb

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:

Case #0: 799653579.133090
Case #1: 3414213562.373095
Case #0: 866.071591
Case #0: 62459.895370
Case #0: 59141.918359
Case #0: 898195.090968
Case #1461552208: 1707085.769987
Case #1452916592: 1686.226798
Case #1: 1686.603546
Case #0: 6806.665584
Case #1: 1907363.078325
Case #1: 1798829.537861
Case #0...

result:

wrong output format Expected '#1:' but found '#0:' (test case 1)