답안 #486284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486284 2021-11-11T07:16:19 Z Nimbostratus Odašiljači (COCI20_odasiljaci) C++17
0 / 70
3 ms 388 KB
#include "bits/stdc++.h"
#define endl '\n'
constexpr int maxn = 105;
constexpr int inf = 1e9;
constexpr int mod = 1e9+7;
using namespace std;
using lint = long long;
using pdd = pair<long double, long double>;
#define x first
#define y second
double eps = 0.0000001;

int n;
pdd pt[maxn];
vector<int> adj[maxn];
bool vis[maxn];

void dfs(int u) {
    vis[u] = true;
    for(int v : adj[u]) {
        if(vis[v])
            continue;
        dfs(v);
    }
}

bool eq(double d1, double d2) {
    return abs(d1 - d2) < eps;
}

bool inter(pdd& a, pdd& b, double r) {
    pdd mid = {(a.x + b.x) / 2, (a.y + b.y) / 2};
    double d1 = sqrt((mid.x - a.x) * (mid.x - a.x) + (mid.y - a.y) * (mid.y - a.y));
    double d2 = sqrt((mid.x - b.x) * (mid.x - b.x) + (mid.y - b.y) * (mid.y - b.y));
    return d1 < r && d2 < r;
}

bool check(double r) {
    for(int i = 0; i < n; i++) {
        vis[i] = false;
        adj[i].clear();
    }
    for(int i = 0; i < n; i++)
        for(int j = 1; j < n; j++)
            if(inter(pt[i], pt[j], r)) {
                adj[i].push_back(j);
                adj[j].push_back(i);
            }
    dfs(0);
    for(int i = 0; i < n; i++)
        if(!vis[i])
            return false;
    return true;
}

signed main() {
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> pt[i].x >> pt[i].y;
    double l = 0, r = 1e9, m;
    while(!eq(l, r)) {
        m = (l + r) / 2;
        if(check(m))
            r = m;
        else
            l = m;
    }
    cout << setprecision(7) << fixed <<  l << endl;
}

Compilation message

odasiljaci.cpp: In function 'int main()':
odasiljaci.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     freopen("in.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
odasiljaci.cpp:59:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     freopen("out.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 388 KB Unexpected end of file - double expected
2 Incorrect 2 ms 332 KB Unexpected end of file - double expected
3 Incorrect 2 ms 332 KB Unexpected end of file - double expected
4 Incorrect 2 ms 332 KB Unexpected end of file - double expected
5 Incorrect 2 ms 332 KB Unexpected end of file - double expected
6 Incorrect 2 ms 332 KB Unexpected end of file - double expected
7 Incorrect 2 ms 332 KB Unexpected end of file - double expected
8 Incorrect 3 ms 388 KB Unexpected end of file - double expected
9 Incorrect 2 ms 332 KB Unexpected end of file - double expected
10 Incorrect 2 ms 332 KB Unexpected end of file - double expected