QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#797864 | #3594. Weird Flecks, But OK | LaVuna47# | WA | 0ms | 3892kb | C++20 | 3.8kb | 2024-12-03 19:58:42 | 2024-12-03 19:58:48 |
Judging History
answer
/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
struct Point {
double x, y;
};
double dist(const Point& a, const Point& b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
struct Circle {
Point center;
double radius;
};
Circle make_circle_two_points(const Point& p1, const Point& p2) {
Point center = {(p1.x + p2.x) / 2.0, (p1.y + p2.y) / 2.0};
double radius = dist(p1, center);
return {center, radius};
}
Circle make_circle_three_points(const Point& p1, const Point& p2, const Point& p3) {
double A = p2.x - p1.x, B = p2.y - p1.y;
double C = p3.x - p1.x, D = p3.y - p1.y;
double E = A * (p1.x + p2.x) + B * (p1.y + p2.y);
double F = C * (p1.x + p3.x) + D * (p1.y + p3.y);
double G = 2 * (A * (p3.y - p2.y) - B * (p3.x - p2.x));
if (fabs(G) < 1e-9) return {{0, 0}, numeric_limits<double>::max()}; // Collinear points
Point center = {(D * E - B * F) / G, (A * F - C * E) / G};
double radius = dist(center, p1);
return {center, radius};
}
bool is_inside(const Circle& c, const Point& p) {
return dist(c.center, p) <= c.radius + 1e-9;
}
Circle min_enclosing_circle(vector<Point>& points) {
int n = points.size();
Circle min_circle = {{0, 0}, numeric_limits<double>::max()};
// Iterate over all pairs of points
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
Circle c = make_circle_two_points(points[i], points[j]);
for (int k = 0; k < n; ++k) {
if (!is_inside(c, points[k])) {
// Adjust circle to include the third point
c = make_circle_three_points(points[i], points[j], points[k]);
}
}
if (c.radius < min_circle.radius) {
min_circle = c;
}
}
}
return min_circle;
}
int solve()
{
int n;
if(!(cin>>n))return 1;
vector<array<double,3>> A(n);
FOR(i,0,n)FOR(j,0,3)cin>>A[i][j];
shuffle(all(A),rnd);
vector<Point> p1(n), p2(n), p3(n);
FOR(i,0,n)p1[i]={A[i][0],A[i][1]};
FOR(i,0,n)p2[i]={A[i][0],A[i][2]};
FOR(i,0,n)p3[i]={A[i][1],A[i][2]};
Circle c1 = min_enclosing_circle(p1);
Circle c2 = min_enclosing_circle(p2);
Circle c3 = min_enclosing_circle(p3);
double res =min(c1.radius,min(c2.radius,c3.radius));
cout << fixed << setprecision(10) << 2*res << '\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cout << "__________________________" << endl;
#endif
}
#ifdef ONPC
cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
input:
3 1.0 0.0 1.4 -1.0 0.0 -1.4 0.0 1.0 -0.2
output:
2.0000000000
result:
ok found '2.00000', expected '2.00000', error '0.00000'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3892kb
input:
5 1.4 1.0 0.0 -0.4 -1.0 0.0 -0.1 -0.25 -0.5 -1.2 0.0 0.9 0.2 0.5 0.5
output:
1.0565866309
result:
wrong answer 1st numbers differ - expected: '2.00000', found: '1.05659', error = '0.47171'