Submission #653849

# Submission time Handle Problem Language Result Execution time Memory
653849 2022-10-28T13:42:25 Z haojiandan Fences (JOI18_fences) C++14
100 / 100
13 ms 684 KB
// wygzgyw
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
template <typename T> void write(T t) {
	if (t<0) { putchar('-'); write(-t); return; }
	if (t>9) write(t/10);
	putchar('0'+t%10);
}
template <typename T> void writeln(T t) { write(t); puts(""); }
#define MP make_pair
const double PIE=acos(-1.0);
const int maxn=220;
const double eps=1e-5;
int n; double S;
struct node {
	double x,y;
	void get() { read(x),read(y); }
	friend node operator + (node A,node B) { return (node){A.x+B.x,A.y+B.y}; }
	friend node operator - (node A,node B) { return (node){A.x-B.x,A.y-B.y}; }
	friend double operator * (node A,node B) { return A.x*B.x+A.y*B.y; }
	friend double operator ^ (node A,node B) { return A.x*B.y-A.y*B.x; }
	friend node operator * (double a,node b) { return (node){b.x*a,b.y*a}; }
	friend node operator * (node b,double a) { return (node){b.x*a,b.y*a}; }
};
struct seg {
	node a,b;
	double len() { node c=b-a; return c.x*c.x+c.y*c.y; }
	node query(node c) {
		if (fabs(a.x-b.x)<eps&&fabs(a.y-b.y)<eps) return a;
		node delta=b-a;
		double lamda=(delta*(c-a))/(delta*delta);
		if (lamda<0) lamda=0;
		if (lamda>1) lamda=1;
		return a+lamda*delta;
	}
} d[maxn],line,s[4];
double dis[maxn][maxn];
int Query(node a,seg b) {
	double tmp=(a-b.a)^(a-b.b);
	if (tmp>eps) return 1;
	if (tmp<eps) return 2;
	return 0;
}
bool check(seg A) {
	node a=A.a,b=A.b;
	if (min(a.x,b.x)>S-eps) return 1;
	if (max(a.x,b.x)<-S+eps) return 1;
	if (min(a.y,b.y)>S-eps) return 1;
	if (max(a.y,b.y)<-S+eps) return 1;/*
	if (a.x>b.x) swap(a,b);
	node delta=b-a;
	if (a.x<S&&S<b.x) {
		node c=a+delta*((S-a.x)/(b.x-a.x));
		if (-S<c.y&&c.y<S) return 0;
	}
	if (a.x<-S&&-S<b.x) {
		node c=a+delta*((-S-a.x)/(b.x-a.x));
		if (-S<c.y&&c.y<S) return 0;
	}
	if (a.y>b.y) swap(a,b);
	delta=b-a;
	if (a.y<S&&S<b.y) {
		node c=a+delta*((S-a.y)/(b.y-a.y));
		if (-S<c.x&&c.x<S) return 0;
	}
	if (a.y<-S&&-S<b.y) {
		node c=a+delta*((-S-a.y)/(b.y-a.y));
		if (-S<c.x&&c.x<S) return 0;
	}
	return 1;*/
	int res=0;
	res|=Query(d[n].a,A);
	res|=Query(d[n-1].a,A);
	res|=Query(d[n-2].a,A);
	res|=Query(d[n-3].a,A);
	return res!=3;
}
int Query(node a,node b) {
	double tmp=(a.x*b.y-a.y*b.x);
	if (tmp<eps) return 1;
	if (tmp>eps) return 2;
	return 0;
}
bool query(seg A) {
	node a=A.a,b=A.b;
	if ((Query(a,line.b)|Query(b,line.b))!=3) return 0;
	double k2=line.b.y/line.b.x;
	if (fabs(a.x-b.x)<eps) return min(0.0,line.b.x)<=a.x&&a.x<=max(0.0,line.b.x)&&min(0.0,line.b.y)<=a.x*k2&&a.x*k2<=max(0.0,line.b.y);
	double k=(b.y-a.y)/(b.x-a.x);
	if (fabs(k-k2)<eps) assert(0);
	double B=b.y-k*b.x;
	double x=B/(k2-k);
	return min(0.0,line.b.x)<=x&&x<=max(0.0,line.b.x);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(S);
	for (int i=1;i<=n;i++) d[i].a.get(),d[i].b.get();
	d[++n]=(seg){(node){-S,-S},(node){-S,-S}};
	d[++n]=(seg){(node){-S,S},(node){-S,S}};
	d[++n]=(seg){(node){S,S},(node){S,S}};
	d[++n]=(seg){(node){S,-S},(node){S,-S}};
	
	double alpha=PIE*(rand()%200)*0.01;
	double T=1e4;
	line.a.x=line.a.y=0;
	line.b=(node){T*cos(alpha),T*sin(alpha)};
	//printf("%.5lf %.5lf\n",line.b.x,line.b.y);
	for (int i=1;i<=n*2;i++) for (int j=1;j<=n*2;j++) dis[i][j]=(i==j?0:1e9);
	for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) {
		
		s[0]=(seg){d[i].a,d[j].query(d[i].a)};
		s[1]=(seg){d[i].b,d[j].query(d[i].b)};
		s[2]=(seg){d[j].a,d[i].query(d[j].a)};
		s[3]=(seg){d[j].b,d[i].query(d[j].b)};
		int k=0; for (int v=1;v<4;v++) if (s[k].len()>s[v].len()) k=v;
		if (!check(s[k])) continue;
		bool res=query(s[k]);
		if (k==0) res^=query((seg){d[j].a,s[0].b});
		if (k==1) res^=query(d[i])^query((seg){d[j].a,s[1].b});
		if (k==2) res^=query((seg){d[i].a,s[2].b});
		if (k==3) res^=query(d[j])^query((seg){d[i].a,s[3].b});
		if (res) dis[i][j+n]=dis[i+n][j]=dis[j+n][i]=dis[j][i+n]=sqrt(s[k].len());
		else dis[i][j]=dis[j][i]=dis[i+n][j+n]=dis[j+n][i+n]=sqrt(s[k].len());
	//	printf("%d %d %.5lf %d, %.5lf %.5lf\n",i,j,sqrt(s[k].len()),res,s[k].b.x,s[k].b.y);
	}
	for (int k=1;k<=n*2;k++) for (int i=1;i<=n*2;i++) for (int j=1;j<=n*2;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	double ans=1e9;
	for (int i=1;i<=n;i++) ans=min(ans,dis[i][i+n]);
	printf("%.5lf\n",ans);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 316 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 316 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 308 KB Output is correct
44 Correct 8 ms 596 KB Output is correct
45 Correct 9 ms 684 KB Output is correct
46 Correct 8 ms 596 KB Output is correct
47 Correct 13 ms 672 KB Output is correct
48 Correct 9 ms 568 KB Output is correct
49 Correct 9 ms 596 KB Output is correct
50 Correct 12 ms 680 KB Output is correct
51 Correct 8 ms 596 KB Output is correct
52 Correct 9 ms 676 KB Output is correct
53 Correct 9 ms 680 KB Output is correct
54 Correct 9 ms 596 KB Output is correct
55 Correct 9 ms 596 KB Output is correct
56 Correct 9 ms 568 KB Output is correct
57 Correct 9 ms 596 KB Output is correct
58 Correct 9 ms 596 KB Output is correct
59 Correct 12 ms 680 KB Output is correct
60 Correct 8 ms 568 KB Output is correct
61 Correct 9 ms 596 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 8 ms 596 KB Output is correct
65 Correct 8 ms 596 KB Output is correct
66 Correct 10 ms 596 KB Output is correct
67 Correct 10 ms 596 KB Output is correct
68 Correct 8 ms 596 KB Output is correct
69 Correct 9 ms 564 KB Output is correct
70 Correct 10 ms 660 KB Output is correct
71 Correct 8 ms 596 KB Output is correct
72 Correct 8 ms 596 KB Output is correct