Skip to content

Commit 24b2afa

Browse files
committed
add: ๋ฐฑ์ค€/Count Circle Group
1 parent 9e2b124 commit 24b2afa

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
const fs = require('fs');
2+
const stdin = (process.platform === 'linux'
3+
? fs.readFileSync('/dev/stdin').toString().trim()
4+
: `2
5+
2
6+
0 0 1
7+
1 0 1
8+
3
9+
0 0 1
10+
2 0 1
11+
10 0 5
12+
`
13+
).split('\n');
14+
15+
const input = (() => {
16+
let line = 0;
17+
return () => stdin[line++];
18+
})();
19+
20+
const parent = {};
21+
const rank = {};
22+
23+
// ์•„๋ž˜ ์„ธ๊ฐœ์˜ ํ•จ์ˆ˜๋Š” ์Šน์˜๋‹˜ ์ฝ”๋“œ ์ฐธ๊ณ (์ตœ์ ํ™”๋œ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ)
24+
function init(v) {
25+
parent[v] = v;
26+
rank[v] = 0;
27+
}
28+
29+
function findParent(v) {
30+
if (parent[v] !== v) {
31+
parent[v] = findParent(parent[v]);
32+
}
33+
return parent[v];
34+
}
35+
36+
function unionParent(v, u) {
37+
const root1 = findParent(v);
38+
const root2 = findParent(u);
39+
if (root1 !== root2) {
40+
if (rank[root1] > rank[root2]) {
41+
parent[root2] = root1;
42+
} else {
43+
parent[root1] = root2;
44+
if (rank[root1] == rank[root2]) {
45+
rank[root2]++;
46+
}
47+
}
48+
}
49+
}
50+
51+
let T = parseInt(input());
52+
53+
for (let tc = 0; tc < T; tc++) {
54+
let N = parseInt(input());
55+
let arr = Array.from(Array(N), () => Array(3).fill(0));
56+
for (let i = 0; i < N; i++) {
57+
const [x, y, r] = input()
58+
.split(' ')
59+
.map((each) => parseInt(each));
60+
61+
arr[i][0] = x;
62+
arr[i][1] = y;
63+
arr[i][2] = r;
64+
init(i);
65+
}
66+
67+
let answer = N;
68+
69+
for (let i = 0; i < N; i++) {
70+
for (let j = i + 1; j < N; j++) {
71+
let xPos = arr[i][0] - arr[j][0];
72+
let yPos = arr[i][1] - arr[j][1];
73+
let radius = arr[i][2] + arr[j][2];
74+
let edistPow = Math.pow(xPos, 2) + Math.pow(yPos, 2); // ์œ ํด๋ฆฌ๋“œ ๊ฑฐ๋ฆฌ์˜ ์ œ๊ณฑ
75+
if (edistPow <= Math.pow(radius, 2)) {
76+
if (findParent(i) !== findParent(j)) {
77+
unionParent(i, j);
78+
answer--;
79+
}
80+
}
81+
}
82+
}
83+
console.log(answer);
84+
}
85+
86+
/*
87+
88+
## How
89+
์–ด๋ ค์› ๋‹ค. ์ขŒํ‘œ์ƒ์— ์›์ด ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ณด์ž ๋‘ ์›์ด ๊ฒน์น˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ? ์œ ํด๋ฆฌ๋“œ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•˜๊ณ  ๊ฐ๊ฐ์˜ ๋ฐ˜์ง€๋ฆ„์„ ๋”ํ•œ ๊ฒƒ๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€์ง€ ๋ณด๋ฉด ๋œ๋‹ค.
90+
91+
์œ ํด๋ฆฌ๋“œ ๊ฑฐ๋ฆฌ๋Š” ํ”ผํƒ€๊ณ ๋ผ์Šค ์ •์˜๋ฅผ ํ†ตํ•ด ์œ ๋„ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‘๊ฐœ์˜ ์ขŒํ‘œ์˜ x์™€ y์˜ ๊ฐ’์˜ ๊ฐ๊ฐ์˜ ์ฐจ์ด๋ฅผ ์ œ๊ณฑํ•˜์—ฌ ๋”ํ•œ ๋’ค ๋ฃจํŠธ๋ฅผ ์”Œ์šฐ๋ฉด ๋‘ ์  ๊ฐ„์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ทœ์น™์ด๋‹ค.(์ƒ๋‹จ์˜ ์ฝ”๋“œ๋Š” ์ด ๊ทœ์น™์— ๋Œ€ํ•ด ์ œ๊ณฑ์„ ํ•ด์„œ ๊ตฌํ–ˆ๋‹ค)
92+
93+
์ด๋ ‡๊ฒŒ ์œ ํด๋ฆฌ๋“œ ๊ฑฐ๋ฆฌ๋ฅผ ์ด์šฉํ•ด ๋‘ ์  ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•˜๊ณ  ๊ทธ๊ฒƒ์ด ๊ฐ ์ขŒํ‘œ์— ํ•ด๋‹นํ•˜๋Š” ์›์˜ ๋ฐ˜์ง€๋ฆ„๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด ๋‘ ์›์ด ๊ฒน์ณ์žˆ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
94+
95+
๋‘ ์›์ด ๊ฒน์นœ๋‹ค๋Š” ์กฐ๊ฑด์ด ๋งž๋‹ค๋ฉด ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ๋ฅผ ์ด์šฉํ•ด ์ตœ์ƒ์˜ ๋…ธ๋“œ๊ฐ€ ๋‹ค๋ฅด๋‹ค๋ฉด ๋‘ ํŠธ๋ฆฌ๋ฅผ ํ•ฉ์นœ ๋’ค N๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” count๋ฅผ 1์”ฉ ๊ฐ์†Œ์‹œํ‚ค๋Š” ์‹์œผ๋กœ ๋ฌธ์ œ์˜ ์š”๊ตฌ์‚ฌํ•ญ์ธ ์ ๊ตฐ ์ง„์˜์˜ ๊ทธ๋ฃน ๊ฐฏ์ˆ˜๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.
96+
97+
## Retrospective
98+
99+
*/

0 commit comments

Comments
ย (0)