QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664891#9348. Driverless Carskip2004AC ✓2399ms4300kbC++205.9kb2024-10-21 23:11:152024-10-21 23:11:15

Judging History

This is the latest submission verdict.

  • [2024-10-21 23:11:15]
  • Judged
  • Verdict: AC
  • Time: 2399ms
  • Memory: 4300kb
  • [2024-10-21 23:11:15]
  • Submitted

answer

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
namespace rgs = std::ranges;
using std::cin, std::cout;
using db = long double;
using cp = std::complex<db>;
const db eps = 1e-8;
db dot(cp u, cp v) {
	return u.real() * v.real() + u.imag() * v.imag();
}
db cross(cp u, cp v) {
	return u.real() * v.imag() - u.imag() * v.real();
}
cp r90(cp x) {
	return cp(-x.imag(), x.real());
}
struct hp : cp {
	db z;
	hp(cp o, db v = 0) : cp(o), z(v) {}
	hp pass(cp o) const {
		return hp(cp(*this), -dot(*this, o));
	}
	db val(cp v) const {
		return dot(v, *this) + z;
	}
	bool test(cp v) const {
		return val(v) >= -eps;
	}
};
using hps = std::vector<hp>;
cp get() {
	int x, y;
	cin >> x >> y;
	return cp(x, y);
}

hps R;
std::vector<cp> inter(hp x, hp y) {
	if(fabs(cross(x, y)) < eps) return {};
	return {
		cp(cross(cp(x.z, x.imag()), cp(y.z, y.imag())), cross(cp(x.real(), x.z), cp(y.real(), y.z)))/
			-cross(x, y)
	};
}
std::vector<cp> points;
const int N = 200;
db dist[N][N];
int getid(cp p) {
	for(int i = 0;i < (int) points.size();++i) {
		if(abs(p - points[i]) < eps) {
			return i;
		}
	}
	points.emplace_back(p);
	int id = points.size() - 1;
	for(int i = 0;i < id;++i) {
		dist[i][id] = 1e18;
		dist[id][i] = 1e18;
	}
	dist[id][id] = 0;
	return points.size() - 1;
}
void link(cp u, cp v, db d) {
	 // cout << "LINK " << u << ' ' << v << ' ' << d << '\n';
	int x = getid(u);
	int y = getid(v);
	dist[x][y] = std::min(dist[x][y], d);
	dist[y][x] = std::min(dist[y][x], d);
}
bool contains(const hps & R, cp p) {
	int ok = 1;
	for(const auto & l : R) {
		ok = ok && l.test(p);
	}
	return ok;
}
void add(const hps & R, hp l) {
	std::vector<cp> v;
	for(auto u : R) {
		for(auto p : inter(u, l)) {
			int ok = contains(R, p);
			for(auto pp : v) {
				ok = ok && abs(p - pp) > eps;
			}
			if(ok) {
				v.push_back(p);
			}
		}
	}
	assert(v.size() <= 2);
	if(v.size() == 2) {
		link(v[0], v[1], abs(v[0] - v[1]));
	}

}
void PP(auto u, auto v) {
	hps t = R;
	t.push_back(u.second);
	t.push_back(v.second);
	cp x = u.first, y = v.first;
	cp d = x - y;
	d /= abs(d);
	add(t, hp(d).pass((x + y) / (db)2));
}
std::vector<db> roots(db A, db B, db C) {
	db delta = B * B - 4 * A * C;
	if(delta < -eps) return {};
	delta = sqrt(std::max<db>(delta, 0));
	return {
		(-B - delta) / 2 / A,
		(-B + delta) / 2 / A,
	};
}
void PL(auto u, auto v) {
	hps t = R;
	t.push_back(u.second);
	// cout << u.second << '\n';
	t.push_back(v[1]); t.push_back(v[2]);
	cp x = u.first; hp l = v[0];
	cp rot = cp(l) / cp(0, 1);
	rot /= abs(rot);

	x /= rot;
	for(auto & l : t) l /= rot;
	l /= rot;
	db h = -l.z / l.imag();
	db a = x.real(), b = x.imag();
	if(fabs(b - h) < eps) {
		return ;
	}
	db A = 1, B = -2 * a, C = a * a + b * b - h * h;
	A /= 2 * (b - h);
	B /= 2 * (b - h);
	C /= 2 * (b - h);
	auto f = [&](db x) {
		return A * x * x + B * x + C;
	};
	std::vector<db> inters;
	// std::cout << "debug : ########### " << x * rot << std::endl;
	for(auto l : t) {
		// cout << cp(l) << ' ' << l.z << '\n';
		if(fabs(l.imag()) < eps) {
			inters.push_back(-l.z / l.real());
		} else {
			for(db x : roots(A, B + l.real() / l.imag(), C + l.z / l.imag())) {
				inters.push_back(x);
				cp p(x, f(x));
			}
		}
	}

	sort(inters.begin(), inters.end());
	inters.erase(unique(inters.begin(), inters.end(), [](db x, db y) { return fabs(x - y) < eps; }), inters.end());
	inters.erase(remove_if(inters.begin(), inters.end(), [&](db x) {
		return !contains(t, cp(x, f(x)));
	}), inters.end());
	for(int i = 1;i < (int) inters.size();++i) {
		db l = inters[i - 1], r = inters[i];
		db mid = (l + r) / 2;
		if(contains(t, cp(mid, f(mid)))) {
			auto integral = [](db a, db b, db c, db x) {
				db val = a * x * x + b * x + c, sval = sqrt(val);
				db s0 = (2 * a * x + b) / 4 / a * sval;
				db s1 = (4 * a * c - b * b) / (8 * sqrt(a * a * a)) * log(fabs(2 * a * x + b + 2 * sqrt(a) * sval));
				return s0 + s1;
			};
			db fa = 4 * A * A, fb = 4 * A * B, fc = B * B + 1;
			db len = integral(fa, fb, fc, r) - integral(fa, fb, fc, l);
			link(cp(l, f(l)) * rot, cp(r, f(r)) * rot, len);
		}
	}
}
void LL(auto u, auto v) {
	hps t = R;
	t.push_back(u[1]); t.push_back(u[2]);
	t.push_back(v[1]); t.push_back(v[2]);
	for(db z : {-1, 1}) {
		cp dir = u[0] + z * v[0];
		hp l(dir);
		l.z = (u[0].z + z * v[0].z);

		if(abs(dir) > eps) {
			l.z /= abs(dir);
			l /= abs(dir);
		}
		add(t, l);
	}
}

void solve() {
	cp l = get(), r = get();
	R = {
		hp(cp(1, 0)).pass(l),
		hp(cp(0, 1)).pass(l),
		hp(cp(-1, 0)).pass(r),
		hp(cp(0, -1)).pass(r),
	};
	auto input = [&]() {
		cp u = get();
		cp v = get();
		cp d = v - u;
		d /= abs(d);
		std::pair A(u, hp(-d).pass(u));
		std::pair B(v, hp(d).pass(v));
		std::array<hp, 3> C{hp(r90(d)).pass(u), hp(d).pass(u), hp(-d).pass(v)};
		return std::tuple(std::array{A, B}, C);
	};
	auto [A0, B0] = input();
	auto [A1, B1] = input();
	for(auto u : A0)
		for(auto v : A1)
			PP(u, v);
	for(auto u : A0)
		PL(u, B1);
	for(auto u : A1)
		PL(u, B0);
	LL(B0, B1);
	// for(auto c : points) {
	// 	cout << c << '\n';
	// }
	int N = points.size();
	for(int k = 0;k < N;++k) {
		for(int i = 0;i < N;++i) {
			for(int j = 0;j < N;++j) {
				dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	std::vector<int> edge_ids;
	for(int i = 0;i < N;++i) {
		int ok = 0;
		for(auto l : R) {
			ok = ok || fabs(l.val(points[i])) < eps;
		}
		if(ok) edge_ids.push_back(i);
	}
	db ans = 1e18;
	for(int i : edge_ids)
		for(int j : edge_ids) if(i != j) {
			ans = std::min(ans, dist[i][j]);
		}
	if(ans > 1e15) {
		puts("0");
	} else {
		printf("%.20Lf\n", ans);
	}
	points = {};
}
int main() {
#ifdef zqj
	freopen("$.in", "r", stdin);
#endif
	std::ios::sync_with_stdio(false), cin.tie(0);
	int t;
	cin >> t;
	for(int i = 0;i < t;++i) {
		solve();
	}
}


这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

1
0 0 7 6
2 4 4 4
3 2 5 2

output:

7.55259359386868112628

result:

ok found '7.552593594', expected '7.552593594', error '0.000000000'

Test #2:

score: 0
Accepted
time: 2073ms
memory: 4180kb

input:

100000
677 -490 687 -487
678 -488 681 -489
686 -488 679 -488
753 896 758 902
756 899 755 901
754 898 754 899
-786 69 -781 81
-784 75 -782 78
-784 71 -782 72
-879 110 -874 114
-878 111 -877 113
-877 112 -876 113
331 -97 340 -89
333 -92 337 -92
337 -90 332 -90
-26 -647 -22 -644
-23 -645 -24 -645
-25 -...

output:

5.75686196586872538181
6.00812680715070695234
5.35580713619144905321
4.62979618237255423959
9.15826280818444577077
5.12401427413882800711
3.00000000000000000000
15.77151982662963628466
5.98999714508478736793
5.76104381601022913061
4.33500524517329864811
4.11755880370422924688
4.42193694176014892062
...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 2143ms
memory: 4064kb

input:

100000
972 368 975 377
974 369 973 372
973 375 974 371
240 -78 247 -47
246 -53 246 -71
245 -72 241 -77
186 465 191 470
188 466 187 467
188 467 189 467
492 14 495 19
493 16 494 16
493 18 493 17
-846 741 -837 749
-842 746 -843 745
-844 747 -845 745
-974 -454 -957 -425
-959 -432 -963 -447
-970 -437 -97...

output:

4.53178816486065182308
8.39428582939212738784
6.19725595771967634629
3.39052975603128570387
8.58372244791840262497
30.32844514374742326407
8.29562313160479357192
7.08141019083600579964
4.90223504527387447804
5.38837269208694474854
18.24131259764494894689
7.41122574488512872578
4.39052975603128539661...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 2190ms
memory: 4300kb

input:

100000
-552 124 -546 142
-550 137 -550 135
-548 131 -550 128
-729 823 -693 829
-696 828 -708 824
-713 826 -726 825
-679 26 -630 48
-645 27 -635 42
-647 42 -666 46
45 462 58 504
50 497 49 496
49 463 55 485
-540 -897 -498 -877
-537 -893 -532 -896
-532 -887 -518 -878
-687 275 -660 284
-668 281 -681 278...

output:

6.59726309280214172565
6.44597211202734756905
34.49119842579261330240
14.57877601900724322953
29.33476998347641841701
10.15380391550348292487
13.39036751335402663111
44.67748708970504183113
4.19725595771969696738
7.00388780924169604501
24.11219819220490760345
29.47004219982798080280
5.78329514041518...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 2217ms
memory: 4212kb

input:

100000
-600 779 -580 835
-583 825 -599 821
-599 780 -590 804
568 374 591 401
572 395 589 384
569 389 569 379
408 -465 420 -412
414 -427 418 -433
419 -446 410 -427
-369 488 -251 542
-275 500 -334 528
-326 511 -349 505
328 704 452 713
372 706 421 705
336 711 422 712
-155 -404 -142 -360
-146 -382 -152 ...

output:

20.95662424316927493692
23.76558400418772273345
28.33598805693156643531
81.89035634616220526993
89.09858700422374305772
17.03140114014833106544
20.14122474529200053361
12.18195003370688445435
49.63958535976336379839
21.25128502671555203417
41.42699486967900103507
89.35432597912194025574
32.374396746...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 2253ms
memory: 4068kb

input:

100000
573 365 736 461
581 379 630 396
594 408 688 387
-715 305 -708 378
-711 337 -713 324
-710 313 -710 331
145 610 165 670
147 613 155 646
152 657 161 647
96 -426 112 -282
98 -377 102 -368
111 -398 101 -417
-622 757 -542 815
-553 798 -569 762
-607 789 -561 800
631 -709 670 -484
653 -637 667 -690
6...

output:

93.41631409153894502473
17.29911678745079395628
27.42422729647925432397
18.75571654159408459608
77.77582584147539818131
100.38334047521018107391
11.98434730154335535468
84.74786530752662257887
14.01361794431664090088
71.55442239487165270728
21.83056675780023533733
51.23880200864830939192
150.1487702...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 2236ms
memory: 4180kb

input:

100000
0 254 468 334
29 329 111 296
409 283 367 296
133 558 896 603
796 586 643 598
600 573 248 591
470 -730 508 -437
484 -669 487 -452
494 -582 502 -544
-727 -507 -181 -495
-684 -506 -351 -503
-213 -503 -458 -498
468 -427 917 -235
563 -242 759 -280
546 -262 794 -411
384 -383 642 -376
552 -381 412 -...

output:

80.00000000000000000000
52.05277722744790385931
91.72309138120657294457
125.79529675024563957486
407.07194260314010805790
50.61783355676704205736
37.90900803901597633169
3.00374765917511785877
161.27297480065585334741
31.25591187293028495528
8.07126488226801069598
6.00479808153446571782
47.551644899...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 2307ms
memory: 4208kb

input:

100000
-944 -991 971 974
935 -451 422 -218
492 -497 -499 -150
-401 -239 750 417
494 182 531 213
-297 -69 726 -57
-925 866 992 876
163 868 69 875
-685 874 -307 867
399 103 994 623
966 463 963 413
586 197 751 406
-438 429 166 840
-210 832 -50 642
120 764 149 688
-678 -996 984 886
905 376 947 -228
-568...

output:

2239.92709228339930072060
855.07977427891421778883
10.00226321152609226459
533.18963097389688710059
430.25943979800436753336
1918.56968099827590601425
1465.62891498345587237839
370.95767972216129437779
1309.53515177091818910693
159.80501758972233881939
1115.80714065461041706318
814.02998033013090184...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 2397ms
memory: 4244kb

input:

100000
-1000 -994 995 965
-281 -337 -339 -661
-802 -162 -374 510
-871 -978 963 847
-571 -202 -582 209
600 -916 -623 -784
-996 -926 999 828
369 19 -719 686
933 -674 -830 -623
-824 -924 933 886
595 153 494 -700
-498 -293 120 -202
-929 -971 889 941
207 -650 482 -139
76 96 -144 427
-985 -956 966 942
-95...

output:

2409.60169026292019789359
2261.22766349523009354883
2118.70926842192177508295
2144.90842678060463022405
2449.45754144654871686804
2183.33290795427067232382
1370.97271056102737363247
1987.23609790744713765598
1664.59507170622277671956
2278.66454563375520558921
1917.83255249035482359332
1286.021595624...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 2399ms
memory: 4024kb

input:

100000
-997 -930 998 990
-620 -300 76 146
910 728 -945 566
-997 -985 995 999
-421 -792 -733 773
892 822 302 -315
-990 -996 999 996
-2 -570 981 -903
-800 635 -848 648
-976 -999 971 997
730 -154 -92 -982
-943 290 -944 -215
-981 -991 1000 990
-327 -631 817 -917
-876 -618 895 -371
-999 -994 998 999
628 ...

output:

2324.84054297229845986728
2080.74964987282833517312
2369.83844435345996837228
2279.06202471647776297559
1808.53196605530902685288
2012.84034670726972260368
2917.90646731936319158152
2024.60740701470101532422
2703.18656927082779217741
1929.99514650896792544721
1404.24780747038686967709
2179.977088348...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed