Hướng dẫn giải của Pháo và bóng bay (bản thiếu nhi)

Chỉ dùng lời giải này khi không có ý tưởng, và đừng copy-paste code từ lời giải này. Hãy tôn trọng người ra đề và người làm lời giải.


Nộp code mẫu trước khi tự giải được bài tập là một hành vi có thể bị ban.

Với ràng buộc ~n \ge 5~, ta xác định tâm mặt cầu bằng cách chọn thử một điểm và so sánh khoảng cách với một số lượng điểm nhất định.

  • Lưu ý: khi so sánh ~2~ số thực ~x~, ~y~, ta không thể dùng == mà thay vào đó là: abs(x - y) < eps với eps được xác định dựa theo sai số của đề.

Code tham khảo

#include <bits/stdc++.h>
using namespace std;

/* Macros */
#define reu(i, a, b) for (int i = (a); i <= (b); ++i)
#define red(i, a, b) for (int i = (a); i >= (b); --i)
#define re1u(i, n) for(int i = 0; i < (n); ++i)
#define re1d(i, n) for(int i = (n)-1; i >= 0; --i)
#define deb(x) {cout << #x << ": " << x << '\n';}
#define deb2(x, y) {cout << #x << ": " << x << ' ' << #y << ": " << y << '\n';}
#define pb push_back
#define mp make_pair
#define BIT(s, i) (((s)>>(i))&1)
#define MASK(s) (1ll<<(s))

/* Variables type shortname */
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

/* Regularly used functions */
template<class T> 
bool maximize(T &a, T b) {
    if (a < b) {a = b; return true;}
    return false;
}

template<class T>
bool minimize(T &a, T b) {
    if (a > b) {a = b; return true;}
    return false;
}

/* Main solution */
typedef long double ld;
const int N = 1e5+5;
int n, k;
struct Point {
    ld x, y, z;
    Point(ld x = 0, ld y = 0, ld z = 0): x(x), y(y), z(z) {}
    Point operator + (const Point &a) const {
        return Point (x+a.x, y+a.y, z+a.z);
    }
    Point operator - (const Point &a) const {
        return Point (x-a.x, y-a.y, z-a.z);
    }
    ld norm() const {
        return sqrt(x*x + y*y + z*z);
    }
    void print() {
        cout << x << ' ' << y << ' ' << z << '\n';
    }
} p[N];
Point A;
const ld eps = 0.001;

void Input() {
    cin >> n;
    cin >> A.x >> A.y >> A.z;
    reu(i, 0, n-1) {
        ld x, y, z; cin >> x >> y >> z;
        p[i] = Point(x, y, z);
    }
}

void Solve() {
    const int need = log2(n);
    ld x = 0;
    ld y = 0;
    ld z = 0;
    reu(i, 0, n-1) {
        ld R = (p[i]-p[(i+1)%n]).norm();
        bool ok = true;
        int cnt = 0;
        reu(j, 0, n-1) if (j != i) {
            if (abs((p[i] - p[j]).norm() - R) >= eps) ok = false;
            if (++cnt > need) break;
        }
        if (ok) {
            cout << setprecision(3) << fixed << (A-p[i]).norm() - R;
            return;
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1; //cin >> t;
    while (t--)
    Input(), Solve();
    return 0;
}

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.