QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202539 | #6542. Optimal Quadratic Function | ucup-team1209 | WA | 3248ms | 8196kb | C++20 | 3.4kb | 2023-10-06 11:10:31 | 2023-10-06 11:10:32 |
Judging History
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-9;
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;
}
vec2 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 {damax - damin, dbmax - dbmin};
}
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;
};
for(int i = 0;i < 220;++i) {
vec2 x = center(), d = eval_d(x.x, x.y);
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';
}
auto c = center();
//std::cerr << c.x << '\n';
//std::cerr << c.y << '\n';
db res = eval(c.x, c.y) / 2;
printf("%.10lf\n", double(res * res));
// cout << res * res << '\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8072kb
input:
1 4 0 0 1 3 2 9 3 0
output:
5.0625000008
result:
ok found '5.0625000', expected '5.0625000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 349ms
memory: 8196kb
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.1259970805 121.0000000000 0.8320061813 412780.6071794858 12.2500000000 15750.2500000324 118751.3800863442 880245.5054739254 1.0000000003 15.3633733630 854986.7131654843 20.2500000000 24567.6673811681 881031.5630219078 306.250000...
result:
ok 60 numbers
Test #3:
score: 0
Accepted
time: 170ms
memory: 8044kb
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: -100
Wrong Answer
time: 3248ms
memory: 7096kb
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.0000015994 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000044958 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000001 0.0000000001 0.0000000000 0.0693060015 0.0000004382 0...
result:
wrong answer 6th numbers differ - expected: '0.0000000', found: '0.0000016', error = '0.0000016'