QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202543#6542. Optimal Quadratic Functionucup-team1209WA 6397ms8560kbC++203.5kb2023-10-06 11:16:412023-10-06 11:16:42

Judging History

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

  • [2023-10-06 11:16:42]
  • 评测
  • 测评结果:WA
  • 用时:6397ms
  • 内存:8560kb
  • [2023-10-06 11:16:41]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
using u64 = unsigned long long;
void IOinit() {
	std::ios::sync_with_stdio(false), cin.tie(0);
#ifdef zqj
	freopen("$.in", "r", stdin);
#endif
}
using db = __float128;
int T, n;
const int N = 100000;
const db eps = 1e-13;
db sgn(db x) { return x < -eps ? -1 : x > eps; }
db eq(db x, db y) { return !sgn(x - y); }
struct vec2 {
	db x, y;
	db norm() const { return x * x + y * y; }
	db arg() const { return atan2(y, x); }
};
vec2 r90(vec2 x) { return {-x.y, x.x}; }
vec2 operator + (vec2 x, vec2 y) { return {x.x + y.x, x.y + y.y}; }
vec2 operator - (vec2 x, vec2 y) { return {x.x - y.x, x.y - y.y}; }
vec2 operator / (vec2 x, db y) { return {x.x / y, x.y / y}; }
vec2 operator * (vec2 x, db y) { return {x.x * y, x.y * y}; }
vec2 operator * (db y, vec2 x) { return {x.x * y, x.y * y}; }
db operator * (vec2 x, vec2 y) { return x.x * y.y - x.y * y.x; }
db operator % (vec2 x, vec2 y) { return x.x * y.x + x.y * y.y; }

struct line : vec2 {
	db z;
	// a * x + b * y + c (= or >) 0
	line() = default;
	line(db a, db b, db c) : vec2{a, b}, z(c) {}
	line(vec2 a, vec2 b) : vec2(r90(b - a)), z(a * b) { }
	// 左侧 > 0
	db operator ()(vec2 a) const { return a % vec2(*this) + z; }
	line perp() const { return {y, -x, 0}; } // 垂直
	line para(vec2 o) { return {x, y, z - (*this)(o)}; } // 平行
};
vec2 operator & (line x, line y) {
	return vec2{vec2{x.z, x.y} * vec2{y.z, y.y}, vec2{x.x, x.z} * vec2{y.x, y.z}} / -(vec2(x) * vec2(y));
	// 注意此处精度误差较大,以及 res.y 需要较高精度
}

std::vector<vec2> cut(const std::vector<vec2> & o, line l) {
	std::vector<vec2> res;
	int n = size(o);
	for(int i = 0;i < n;++i) {
		vec2 a = o[i], b = o[(i + 1) % n];
		if(sgn(l(a)) >= 0) res.push_back(a); // 注意 sgn 精度
		if(sgn(l(a)) * sgn(l(b)) < 0) res.push_back(line(a, b) & l);
	}
	return res;
} // 切凸包
db x[N], y[N], o[N];
db eval(db a, db b) {
	db min = y[0] - a * x[0] * x[0] - b * x[0];
	db max = min;
	for(int i = 1;i < n;++i) {
		db v = y[i] - a * x[i] * x[i] - b * x[i];
		if(max < v) max = v;
		if(min > v) min = v;
	}
	return max - min;
}
std::pair<vec2, db> eval_d(db a, db b) {
	db min = y[0] - (a * x[0] * x[0] + b * x[0]), damin = -x[0] * x[0], dbmin = -x[0];
	db max = min, damax = -x[0] * x[0], dbmax = -x[0];
	for(int i = 1;i < n;++i) {
		db v = y[i] - (a * x[i] * x[i] + b * x[i]);
		if(max < v) max = v, damax = -x[i] * x[i], dbmax = -x[i];
		if(min > v) min = v, damin = -x[i] * x[i], dbmin = -x[i];
	}
	return std::make_pair(vec2{damax - damin, dbmax - dbmin}, max - min);
}


int main() {
	IOinit();
	cin >> T;
	for(int i = 0;i < T;++i) {
		cin >> n;
		for(int i = 0;i < n;++i) {
			int a, b; cin >> a >> b;
			x[i] = a;
			y[i] = b;
		}
		const db V = 1e18;
		std::vector<vec2> v = { {-V, -V}, {V, - V}, {V, V}, {-V, V} };
		auto center = [&]() -> vec2 {
			vec2 sum = v[0];
			for(int j = 1;j < (int) v.size();++j) sum = sum + v[j];
			sum = sum / v.size();
			return sum;
		};
		db res = eval(0, 0) / 2;
		for(int i = 0;i < 230;++i) {
			vec2 x = center();
			auto [d, tmp] = eval_d(x.x, x.y);
			res = std::min(res, tmp / 2);
			d.x *= -1, d.y *= -1;
			line L; L.x = d.x, L.y = d.y; L = L.para(x);
			v = cut(v, L);
			assert(v.size());
		}
		for(auto [x, y] : v) {
		//	std::cerr << "de " << x << ' ' << y << '\n';
		}
		// std::cerr << (double)res << '\n';
		printf("%.10lf\n", double(res * res));
		// cout << res * res << '\n';
	}
}

详细

Test #1:

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

input:

1
4
0 0
1 3
2 9
3 0

output:

5.0625000000

result:

ok found '5.0625000', expected '5.0625000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 394ms
memory: 7528kb

input:

60
1
1000 -990
2
171 -638
949 -99
2
633 227
-257 -602
3
634 -994
633 999
-374 995
3
445 -110
586 -121
462 29
9
-995 -224
-458 -833
691 -670
456 -259
-376 55
-563 -12
834 827
-826 -220
299 744
17
997 991
997 976
997 988
998 -986
999 -982
999 -980
999 -996
998 -988
998 -991
997 987
1000 996
999 -1000
...

output:

0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
543160.1259963982
121.0000000000
0.8320061812
412780.6071794284
12.2500000000
15750.2500000000
118751.3800860984
880245.5054735196
1.0000000000
15.3633733603
854986.7131649870
20.2500000000
24567.6673810630
881031.5630210810
306.250000...

result:

ok 60 numbers

Test #3:

score: 0
Accepted
time: 175ms
memory: 7896kb

input:

1000
1
-585478 527569
1
152984 679945
1
-174472 172630
1
235983 471538
1
-250372 650998
1
521028 -109032
1
121457 989514
1
916700 -223410
1
25908 939341
1
999032 369442
1
249207 -874185
1
-921949 719467
1
-692065 -756006
1
580461 644861
1
-382986 975568
1
644060 -113069
1
-588888 717169
1
2947 -3929...

output:

0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0...

result:

ok 1000 numbers

Test #4:

score: 0
Accepted
time: 6397ms
memory: 8560kb

input:

1000
2
578578 -462573
-614596 -50411
2
568651 926188
-15389 -281674
2
-56242 -213116
215036 310015
2
-568452 -743741
-314862 -573269
2
-428037 -926383
-172945 -31965
2
-58020 145819
-69585 116311
2
-629887 -794837
704590 -761914
2
243217 -433618
98814 -457689
2
147490 681479
665176 -119632
2
-851707...

output:

0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 485ms
memory: 5968kb

input:

1000
3
-734917 -489090
419510 102330
712427 633246
3
36286 -456156
747264 -743132
260371 -674274
3
429263 14588
352092 -105774
547767 232534
3
-913665 328259
240305 -680653
-295994 -678964
3
597443 -368402
-231672 43641
-590555 396735
3
-603016 904082
-607928 649743
464117 526551
3
350193 -351624
33...

output:

0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 511ms
memory: 6028kb

input:

1000
4
-48411 -514672
165369 -349660
-281244 -842990
50473 -422110
4
-487482 -318709
861670 -709796
-491931 -335068
-523699 -455262
4
-817575 -338873
869501 905839
-717462 -668516
841972 769497
4
530706 615905
128991 -871809
82920 -948448
-317630 -725769
4
144451 772470
-923425 791489
513030 193835
...

output:

0.0016352549
0.4418888937
0.0950875592
3655702.6519551454
769858.6658160313
876.9644181407
2.3833780367
0.0033143316
0.0460742900
0.4140871969
31534.7528371150
0.0115333108
1322109.7934964325
2475705.1418559174
5494047.0763876298
0.6047581124
36615.9822256014
15433.4438030258
0.0000134834
416.623552...

result:

ok 1000 numbers

Test #7:

score: 0
Accepted
time: 548ms
memory: 5960kb

input:

1000
5
-425128 981633
-381689 946206
957441 996145
84010 712860
-8814 738024
5
235841 662950
864929 -477349
823444 -108225
714735 661226
300163 983888
5
-972539 106077
-856485 556296
-951397 193386
-207377 778279
-862794 555900
5
-877483 818676
537271 -193411
341352 408858
167065 819835
451709 87895...

output:

162.2174236028
24899.7030374493
111166879.5564019531
440.6680439634
45502620.0264690593
0.9081657330
48119370.9382886291
1331743.1073604964
1145.0410543633
11911.4090896976
898995.9310677316
0.2814863986
7.8352654558
0.7705991742
1167.3057075338
40318098119.9603500366
643.4716837268
0.1447506035
459...

result:

ok 1000 numbers

Test #8:

score: 0
Accepted
time: 678ms
memory: 6044kb

input:

1000
10
860001 272235
-30508 220967
711207 504388
77794 647164
303746 959200
592742 534104
57277 254211
266565 968002
919148 568676
991753 -20796
10
95213 204518
35283 198770
69842 203724
-316246 248661
-319918 245804
-923990 767251
-689125 503455
175418 229272
90053 206083
-815528 637145
10
-808164...

output:

52855287328.8024520874
4736213.5450279405
325.2766040547
11692527.6193262469
61306.4670950689
24947264304.3305587769
492734951022.4921264648
0.9653457857
1913.4955047132
385.4746631450
6.4484451827
42078421804.7162780762
5867468.0156366751
0.6066720648
24254772.5148466974
863797.7294305573
9847186.3...

result:

ok 1000 numbers

Test #9:

score: 0
Accepted
time: 1ms
memory: 6020kb

input:

1
4
-1000000 -1000000
-999999 1000000
999999 1000000
1000000 -1000000

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #10:

score: 0
Accepted
time: 1ms
memory: 5788kb

input:

1
4
-1000000 -1000000
-999999 1000000
-999998 1000000
-999997 -100000

output:

12656250000.0001239777

result:

ok found '12656250000.0001240', expected '12656250000.0000000', error '0.0000000'

Test #11:

score: 0
Accepted
time: 1ms
memory: 5856kb

input:

1
4
-1000000 -1000000
-999999 1000000
-999998 1000000
-999997 -1000000

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #12:

score: 0
Accepted
time: 1ms
memory: 5788kb

input:

1
4
-1000000 -300000
-999999 300000
-999998 300000
-999997 -300000

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #13:

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

input:

1
4
-1000000 -999999
-999999 999998
-999998 999996
-999997 -999999

output:

0.5625000003

result:

ok found '0.5625000', expected '0.5625000', error '0.0000000'

Test #14:

score: 0
Accepted
time: 5ms
memory: 6136kb

input:

8
4
-1000000 -1000000
-999999 1000000
999999 999977
1000000 -1000000
4
-1000000 -1000000
-999999 1000000
999999 999770
1000000 -1000000
4
-1000000 -1000000
-999999 1000000
999999 997770
1000000 -1000000
4
-1000000 -1000000
-999999 1000000
999999 977770
1000000 -1000000
4
-1000000 -1000000
-999999 10...

output:

33.0625330625
3306.2533062525
310806.5608064831
30885837.1358294152
62499875000.0000000000
561097185.4489570856
0.5630629222
2770157895.4910011292

result:

ok 8 numbers

Test #15:

score: 0
Accepted
time: 47ms
memory: 6036kb

input:

50
20
-78760 901241
-290160 346799
-100100 886312
-400033 -7842
-128289 858428
-443380 -236792
-204313 613533
870820 96059
812309 226162
-35539 980448
797663 345545
-445875 -256648
-460410 -299719
627726 793426
832862 169452
656272 795052
-339551 196857
-34433 992148
-388395 11457
-255059 482328
20
...

output:

1995515551.2350509167
81676587.1627827436
15097.2399591286
23.3955124295
579359934.0032750368
3853.6636501781
50.3813829640
2611489.3654492688
131464690.0642413348
2137.8200682335
284.1439651693
564775635.7531059980
39822891364.8647537231
909.2738771291
16588.0635715548
2808332.0414695572
2945.34060...

result:

ok 50 numbers

Test #16:

score: -100
Wrong Answer
time: 3539ms
memory: 7836kb

input:

500
300
-574218 -271807
-443150 -83950
15479 867073
-467689 -121944
-318587 129168
-24306 766466
-968754 -612160
-814705 -519500
-60831 677156
-195474 372912
-44244 717366
-134450 505915
-523893 -204101
-179966 405956
-732527 -448979
-886997 -569400
-190507 383431
-538163 -223837
-885831 -568677
-60...

output:

223.5739863687
11176.3428746619
1192.7447535478
453187006.5233573318
554031869.3744086027
9.2061590155
126.7131722673
2.7912251743
7790357819.2904548645
13298746917.7339115143
138873066385.7579040527
4982989809.2843675613
67327474.8779176027
4313.3500237465
2045627.9640001673
5494615758.9164447784
7...

result:

wrong answer 434th numbers differ - expected: '4.6285095', found: '4.6285155', error = '0.0000013'