QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#705177#6752. GeometryTheZoneAC ✓0ms3992kbC++142.9kb2024-11-02 22:25:002024-11-02 22:25:02

Judging History

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

  • [2024-11-02 22:25:02]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3992kb
  • [2024-11-02 22:25:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE
#define debug(...) fprintf(stderr,##__VA_ARGS__)
#else
#define debug(...) ;
#endif

using LL=long long;
using PII=pair<int,int>;

#define eps (1e-12)
inline int sign(const double& x){
	if(fabs(x)<=eps) return 0;
	return x>0.0?1:-1;
}
inline int dcmp(const double& x,const double& y){
	return sign(x-y);
}

using PDD=pair<double,double>;
#define x first
#define y second
PDD operator -(const PDD& A,const PDD& B){
	return {A.x-B.x,A.y-B.y};
}
PDD operator +(const PDD& A,const PDD& B){
	return {A.x+B.x,A.y-B.y};
}
double operator *(const PDD& A,const PDD& B){
	return A.x*B.y-A.y*B.x;
}

bool check(const PDD& A,const PDD& B,const PDD& C){
	PDD P=B-A,Q=C-B;
	return sign(P*Q)==1;
}
double dis(const PDD& A,const PDD& B){
	PDD d=A-B;
	return sqrt(d.x*d.x+d.y*d.y);
}

template<typename T>
inline T READ(){
	T x=0; bool f=0; char c=getchar();
	while(c<'0' || c>'9') f|=(c=='-'),c=getchar();
	while(c>='0' && c<='9') x=x*10+c-'0',c=getchar();
	return f?-x:x;
}
inline int read(){return READ<int>();}
inline LL readLL(){return READ<LL>();}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

#define N 20
int n;
PII a[N][3];

int top_opt=0,top[N];
int opt[N][N];

double ans;
PDD pos[N*3]; int top_pos;
int up[N*3],top_up=0,down[N*3],top_down=0;
inline double calc(){
	double res=0.0;
	for(int i=1;i<=top_opt;i++){
		top_pos=0;
		for(int j=1;j<=top[i];j++){
			pos[++top_pos]=a[opt[i][j]][0];
			pos[++top_pos]=a[opt[i][j]][1];
			pos[++top_pos]=a[opt[i][j]][2];
		}
		sort(pos+1,pos+top_pos+1,[](const PDD& A,const PDD& B){
			if(dcmp(A.y,B.y)==0) return dcmp(A.x,B.x)==-1;
			return dcmp(A.y,B.y)==-1;
		});
		up[top_up=1]=1;
		for(int i=2;i<=top_pos;i++){
			while(top_up>=2 && !check(pos[up[top_up-1]],pos[up[top_up]],pos[i])) top_up--;
			up[++top_up]=i;
		}
		down[top_down=1]=up[top_up];
		for(int i=top_pos-1;i>0;i--){
			while(top_down>=2 && !check(pos[down[top_down-1]],pos[down[top_down]],pos[i])) top_down--;
			down[++top_down]=i;
		}
		for(int i=1;i<top_up;i++) res+=dis(pos[up[i]],pos[up[i+1]]);
		for(int i=1;i<top_down;i++) res+=dis(pos[down[i]],pos[down[i+1]]);
	}
	return res;
}

void dfs(int u){
	if(u>n){
		ans=min(ans,calc());
		return;
	}
	if(calc()>ans) return;
	++top_opt;
	opt[top_opt][top[top_opt]=1]=u;
	dfs(u+1);
	top[top_opt--]=0;
	for(int i=1;i<=top_opt;i++){
		opt[i][++top[i]]=u;
		dfs(u+1);
		top[i]--;
	}
}

int main(){
//	freopen("F_in.txt","r",stdin);
	n=read(),ans=0.0;
	for(int i=1;i<=n;i++){
		a[i][0].x=read(),a[i][0].y=read();
		a[i][1].x=read(),a[i][1].y=read();
		a[i][2].x=read(),a[i][2].y=read();
		ans+=dis(a[i][0],a[i][1])+dis(a[i][1],a[i][2])+dis(a[i][2],a[i][0]);
	}
	top_opt=1,top[1]=n;
	for(int i=1;i<=n;i++) opt[1][i]=i;
	ans=min(ans,calc());
	top_opt=top[1]=0;
	dfs(1);
	printf("%.12lf\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3928kb

input:

2
0 0 1 0 0 1
100 100 101 100 100 101

output:

6.828427124746

result:

ok found '6.82843', expected '6.82843', error '0.00000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

2
0 0 0 1 1 0
1 0 0 1 1 1

output:

4.000000000000

result:

ok found '4.00000', expected '4.00000', error '0.00000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3992kb

input:

14
3 0 0 2 0 1
3 3 2 0 0 1
2 0 3 2 2 0
3 2 3 1 0 3
0 0 1 3 1 2
3 2 2 2 0 1
1 2 1 0 3 2
0 0 0 3 3 2
2 1 3 2 2 2
2 1 0 1 1 0
2 0 3 2 0 2
0 2 3 1 3 3
1 2 0 2 2 0
3 3 3 1 3 1

output:

12.000000000000

result:

ok found '12.00000', expected '12.00000', error '0.00000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3988kb

input:

14
1 2 3 1 0 3
2 1 1 6 2 1
0 5 4 1 1 0
5 6 6 5 2 0
6 6 1 2 0 0
0 0 4 6 1 2
5 2 2 3 0 6
3 1 0 2 3 4
0 0 5 1 5 2
0 6 6 6 3 5
6 1 0 3 2 0
2 1 4 5 6 3
5 2 2 5 2 6
1 4 4 2 4 2

output:

23.123105625618

result:

ok found '23.12311', expected '23.12311', error '0.00000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3932kb

input:

14
9 1 9 3 4 1
0 6 0 2 0 3
0 0 1 5 8 2
9 1 4 2 1 5
1 0 6 6 5 4
3 1 4 2 1 6
1 5 1 8 6 9
6 3 1 8 2 2
6 8 0 3 8 5
0 4 4 7 2 6
4 7 2 8 4 7
6 7 5 5 2 1
2 7 0 7 0 4
8 0 7 5 2 2

output:

31.635650570838

result:

ok found '31.63565', expected '31.63565', error '0.00000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

14
12 12 5 8 4 4
12 1 12 8 3 1
0 10 10 10 10 12
9 2 8 3 5 4
8 9 5 3 8 2
9 9 0 7 8 4
5 2 0 10 4 8
10 4 8 8 2 3
9 5 9 10 1 10
3 5 12 6 5 6
9 0 8 5 1 7
4 11 10 11 6 12
6 11 2 11 10 4
11 3 6 7 12 5

output:

42.312417726083

result:

ok found '42.31242', expected '42.31242', error '0.00000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3920kb

input:

14
5 5 0 13 4 11
5 8 6 13 11 8
1 15 12 4 2 10
7 7 7 11 11 0
6 1 0 0 5 3
14 15 0 8 3 8
6 14 1 8 12 4
14 3 8 15 3 15
7 9 13 7 8 13
15 9 14 12 14 8
2 11 4 11 15 2
14 13 4 15 14 11
6 1 9 8 11 14
9 12 0 14 13 1

output:

56.969112047671

result:

ok found '56.96911', expected '56.96911', error '0.00000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3932kb

input:

14
0 13 2 13 18 8
10 6 3 13 13 3
12 12 13 17 7 18
2 14 18 17 2 11
5 15 6 3 3 4
2 5 17 3 0 10
10 13 15 11 8 9
9 14 4 1 3 15
2 6 2 0 14 15
14 16 18 9 16 7
8 7 17 13 10 3
6 11 3 4 18 13
4 1 13 14 9 17
14 14 14 15 1 1

output:

62.513363039112

result:

ok found '62.51336', expected '62.51336', error '0.00000'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3932kb

input:

14
14 3 16 12 20 0
5 3 19 18 21 4
2 1 4 16 11 2
5 14 3 16 6 2
0 10 8 19 1 20
0 14 9 18 20 7
12 5 16 4 13 6
12 9 13 21 7 13
10 13 11 16 19 11
16 10 16 16 9 17
13 9 18 18 12 0
6 3 1 19 8 20
2 6 2 7 13 0
3 6 10 3 3 2

output:

74.367222369352

result:

ok found '74.36722', expected '74.36722', error '0.00000'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

14
19 0 22 1 10 2
7 0 13 4 18 23
12 8 13 14 0 0
2 11 7 17 24 21
16 4 17 18 0 10
17 3 20 10 16 8
9 17 21 8 0 16
13 23 23 7 17 16
9 17 21 0 21 7
20 18 5 8 4 15
11 6 14 8 6 14
4 21 12 18 15 24
10 23 12 2 9 1
10 13 12 8 18 14

output:

85.846176992157

result:

ok found '85.84618', expected '85.84618', error '0.00000'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

14
19 19 22 26 11 24
6 0 22 26 8 13
15 21 9 10 18 25
12 2 11 3 26 16
24 4 20 3 7 24
12 9 6 12 8 20
13 9 17 0 4 23
5 20 10 19 10 24
27 9 14 21 7 6
17 13 1 8 5 19
5 1 17 8 10 27
21 17 16 8 4 11
27 6 27 5 6 15
20 25 21 0 11 7

output:

88.677874083211

result:

ok found '88.67787', expected '88.67787', error '0.00000'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

14
16 22 6 0 8 27
4 29 30 7 2 11
27 9 13 12 13 7
23 24 26 2 21 15
21 21 0 29 27 3
27 27 21 6 14 10
12 19 25 29 25 21
18 9 11 2 23 24
2 3 29 17 6 25
9 25 20 2 16 6
6 27 2 17 17 29
28 2 21 22 8 12
18 6 18 30 11 27
26 9 3 16 7 5

output:

106.727862424558

result:

ok found '106.72786', expected '106.72786', error '0.00000'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3932kb

input:

14
1 19 18 19 7 20
3 29 22 1 14 13
12 18 9 23 8 4
4 1 2 2 16 2
25 12 16 3 12 13
7 26 1 13 16 19
0 5 15 25 17 1
3 16 4 28 10 9
10 9 7 2 11 27
22 1 0 15 17 31
2 3 16 26 15 33
17 8 11 23 15 15
10 27 22 1 26 32
12 2 30 8 0 8

output:

106.815107908028

result:

ok found '106.81511', expected '106.81511', error '0.00000'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3992kb

input:

14
16 31 30 12 23 4
29 2 32 24 17 16
3 11 28 12 16 5
1 20 30 35 25 13
24 12 26 27 3 7
8 12 5 30 21 1
10 22 4 22 30 9
18 32 27 18 17 5
2 36 9 12 18 30
17 30 14 24 17 3
1 14 9 7 24 23
16 20 33 34 28 21
33 12 12 4 21 30
14 35 29 12 7 17

output:

120.297711867152

result:

ok found '120.29771', expected '120.29771', error '0.00000'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

14
13 18 6 21 16 9
27 17 22 20 10 12
39 33 14 27 15 0
11 35 12 38 4 9
27 3 21 16 28 27
26 22 9 17 14 7
19 39 37 25 29 7
19 22 23 21 10 14
5 10 31 18 13 3
37 2 5 24 18 31
18 38 29 34 26 6
38 35 27 27 14 11
33 15 11 35 36 31
13 10 7 19 4 11

output:

126.782345853161

result:

ok found '126.78235', expected '126.78235', error '0.00000'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

14
20 0 22 13 27 35
41 10 2 37 30 6
33 15 31 0 30 33
11 25 6 12 18 33
10 21 22 38 39 18
11 27 21 34 19 17
24 11 17 23 21 21
35 20 16 5 18 21
0 13 39 10 11 17
21 33 18 32 18 1
17 40 31 9 6 42
18 24 26 10 42 16
39 9 22 19 2 21
38 8 2 29 38 36

output:

138.534563447632

result:

ok found '138.53456', expected '138.53456', error '0.00000'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

14
19 29 27 25 7 23
12 7 38 13 28 5
31 15 37 11 12 39
19 42 6 34 27 4
43 45 16 14 23 31
28 41 45 33 31 2
36 23 11 35 18 24
22 19 15 41 41 3
31 34 2 17 35 16
6 40 1 37 1 28
37 15 23 6 10 27
20 26 34 1 42 18
35 44 17 11 18 36
15 2 4 21 40 12

output:

151.802890277334

result:

ok found '151.80289', expected '151.80289', error '0.00000'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3916kb

input:

14
4 22 11 24 13 30
47 46 17 4 42 47
14 7 21 40 8 10
15 42 28 40 33 6
45 27 16 4 9 19
17 35 23 45 34 11
1 1 5 19 15 24
15 38 32 4 46 23
11 31 37 48 37 26
17 5 23 16 40 25
36 1 18 34 18 13
4 5 2 43 2 33
20 31 3 12 16 4
19 43 27 6 37 32

output:

169.753101975345

result:

ok found '169.75310', expected '169.75310', error '0.00000'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3984kb

input:

14
16 22 20 42 24 44
28 50 15 12 42 49
34 13 30 25 12 41
8 14 36 24 18 41
51 27 13 19 19 46
51 0 1 2 50 12
20 8 20 17 39 0
41 23 11 11 0 15
43 21 19 45 50 51
42 34 29 18 4 46
14 7 49 39 46 49
1 8 8 6 16 15
31 14 24 43 20 14
51 7 30 35 46 1

output:

191.722589173129

result:

ok found '191.72259', expected '191.72259', error '0.00000'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

14
47 15 26 51 52 37
36 32 26 48 22 36
6 48 17 31 43 8
2 50 12 4 14 38
3 8 49 30 11 25
27 45 1 3 21 27
47 20 46 2 26 50
50 37 0 23 33 10
30 17 0 1 37 39
28 54 46 38 26 17
23 22 24 49 45 2
1 33 21 1 5 13
28 13 46 49 4 45
30 26 4 35 19 37

output:

189.008368990085

result:

ok found '189.00837', expected '189.00837', error '0.00000'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3932kb

input:

14
43 53 44 6 29 7
42 41 15 2 10 0
12 25 15 0 49 6
29 19 14 21 27 29
10 3 43 25 18 49
4 36 44 48 12 5
23 27 21 38 21 3
38 22 23 48 57 40
36 22 51 32 30 51
43 16 26 33 7 46
25 20 22 37 1 4
22 19 39 56 39 10
39 44 30 6 21 22
13 30 51 25 12 46

output:

184.514415470116

result:

ok found '184.51442', expected '184.51442', error '0.00000'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

14
58 32 34 36 41 1
37 11 1 27 10 51
32 28 59 33 37 42
60 19 34 5 44 55
42 52 24 19 2 4
52 24 51 9 55 1
53 59 2 50 42 5
32 15 42 5 6 54
1 32 11 58 15 12
18 21 5 12 40 28
44 46 24 5 20 52
49 55 60 27 56 4
22 6 14 48 13 15
7 36 50 15 15 14

output:

212.689124252083

result:

ok found '212.68912', expected '212.68912', error '0.00000'