본문 바로가기

USACO/Silver

백준 14172 Moocast (USACO December 2016 Silver 3번)

문제 링크: https://www.acmicpc.net/problem/14172

 

14172번: Moocast

Write a single line of output containing the maximum number of cows a broadcast from a single cow can reach. The originating cow is included in this number.

www.acmicpc.net

DFS

각 cow마다 얼마나 많은 다른 소한테 연결될수 있는지를 구하고, 그 중 최대값을 구하면 됨.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
 
struct cow {
    int x, y, r;
};
int n, check[201];
vector<cow> v;
 
int dfs(int cur) {
    check[cur] = 1;
    int ret = 1;
    int rr = v[cur].r * v[cur].r;
    for(int nxt = 0; nxt < n; nxt++) {
        int dd = (v[cur].x-v[nxt].x)*(v[cur].x - v[nxt].x) + (v[cur].y-v[nxt].y)*(v[cur].y-v[nxt].y);
        if(!check[nxt] && dd <= rr)
            ret += dfs(nxt);
    }
    return ret;
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x, y, r;
        cin >> x >> y >> r;
        v.push_back({x, y, r});
    }
 
    int ans = 0;
    for(int i = 0; i < n; i++) {
        memset(check, 0sizeof(check));
        ans = max(ans, dfs(i));
    }
 
    cout << ans << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter