문제 링크: https://www.acmicpc.net/problem/5959
5959번: Crop Circles
Bessie and her fellow herd-mates have become extremely territorial. The N (1 <= N <= 400) cows conveniently numbered 1..N have all staked out a grazing spot in the pasture. Each cow i has a spot on an integer grid (0 <= X_i <= 10,000; 0 <= Y_i <= 10,000) a
www.acmicpc.net
두 center 사이의 거리가 두 반지름의 합보다 작으면 겹치는것임.
O(N^2)으로 모든 pair를 확인하면서 세면 됨.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include <bits/stdc++.h>
using namespace std;
int n, x[401], y[401], r[401];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i];
for(int i = 0; i < n; i++) {
int cnt = 0;
for(int j = 0; j < n; j++) {
if(i == j) continue;
if((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) < (r[i] + r[j]) * (r[i] + r[j]))
cnt++;
}
cout << cnt << '\n';
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Bronze' 카테고리의 다른 글
백준 5958 Space Exploration (USACO January 2011 Bronze 3번) (0) | 2020.04.08 |
---|---|
백준 5957 Cleaning the Dishes (USACO January 2011 Bronze 2번) (0) | 2020.04.08 |
백준 5956 Symmetry (USACO January 2011 Bronze 1번) (0) | 2020.04.08 |
백준 5949 Adding Commas (USACO December 2010 Bronze 3번) (0) | 2020.04.06 |
백준 5948 Bad Random Numbers (USACO December 2010 Bronze 2번) (0) | 2020.04.06 |