-
[Algo Rhythm๐บ๐]BOJ 20170 - Commemorative DiceAlgo Rhythm๐บ๐/BOJ 2021. 6. 21. 03:26
๋ฌธ์ ๋ถ์
์ฃผ์ฌ์ ๊ฒ์์ ํ๋ ์ฒซ๋ฒ์งธ, ๋๋ฒ์งธ ํ๋ ์ด์ด๋ฅผ ๊ฐ๊ฐ A, B๋ผ๊ณ ํ๊ณ A์ B์ ์ฃผ์ฌ์ ์ค ์์์ ํ ๋ฉด์ ์ ํ ์ซ์๋ฅผ ๊ฐ๊ฐ $\alpha, \beta$๋ผ๊ณ ํ์.
์ด๋ ์ฃผ์ฌ์๋ 6๋ฉด์ด๊ธฐ ๋๋ฌธ์ A์ B๊ฐ ์ฃผ์ฌ์๋ฅผ ๋์ ธ์ ๋์ฌ ์ ์๋ ๊ฒฝ์ฐ์ ์๋ $6 \times 6 = 36$์ด๋ค.
๊ทธ๋ฆฌ๊ณ A๊ฐ B๋ฅผ ์ด๊ธฐ๋ ๊ฒฝ์ฐ์ ์์ธ $N_{win}$์ $\alpha \gt \beta$๋ฅผ ๋ง์กฑํ๋ ๋ชจ๋ $\alpha$์ ์์ ๊ฐ๋ค.
๋ฐ๋ผ์, A๊ฐ B๋ฅผ ์ด๊ธธ ํ๋ฅ ์ $N_{win} \over 36$์ด๋ค. ์ด๋, ๋ฌธ์ ์์ ์๊ตฌํ๋ ๊ฒ์ '๋์ด์ ๋๋ ์ ์๋' ๋ถ์ ํํ๋ก ์ถ๋ ฅํ๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ๋ถ์์ ๋ถ๋ชจ๋ฅผ ์ต๋ ๊ณต์ฝ์๋ก ๋๋ ์ ์ถ๋ ฅํด์ผ ํ๋ค.
๋ฌธ์ ํ์ด
A์ B์ ์ฃผ์ฌ์ ์ ๋ณด๋ฅผ ๊ฐ๊ฐ ๋ฐฐ์ด์ ์ ์ฅํ ๋ค, $\alpha \gt \beta$๋ฅผ ๋ง์กฑํ๋ $\alpha$์ ์๋ฅผ ๊ตฌํ๋ค.
๊ทธ๋ฆฌ๊ณ ๋ถ์์ ๋ถ๋ชจ์ ์ต๋ ๊ณต์ฝ์๋ฅผ ๊ตฌํ ๋ค ๊ทธ๊ฒ์ผ๋ก ๋๋์ด์ ์ถ๋ ฅํ๋ค.
์ด๋ ์ต๋ ๊ณต์ฝ์๋ฅผ ๊ตฌํ๊ธฐ ์ํด '2๊ฐ์ ์์ฐ์(๋๋ ์ ์) a, b์ ๋ํด์ a๋ฅผ b๋ก ๋๋ ๋๋จธ์ง๋ฅผ r์ด๋ผ ํ๋ฉด(๋จ, a>b), a์ b์ ์ต๋๊ณต์ฝ์๋ b์ r์ ์ต๋๊ณต์ฝ์์ ๊ฐ๋ค.'๋ ์ฑ์ง์ ์ด์ฉํ ์ ํด๋ฆฌ๋ ํธ์ ๋ฒ์ ์ฌ์ฉํ๋ค.
์ ํด๋ฆฌ๋ ํธ์ ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ ์๋๋ฅผ ์ฐธ๊ณ ํ๊ธธ ๋ฐ๋๋ค.
https://ko.wikipedia.org/wiki/์ ํด๋ฆฌ๋_ํธ์ ๋ฒ
์ ํด๋ฆฌ๋ ํธ์ ๋ฒ - ์ํค๋ฐฑ๊ณผ, ์ฐ๋ฆฌ ๋ชจ๋์ ๋ฐฑ๊ณผ์ฌ์
์ํค๋ฐฑ๊ณผ, ์ฐ๋ฆฌ ๋ชจ๋์ ๋ฐฑ๊ณผ์ฌ์ . ์ ํด๋ฆฌ๋ ํธ์ ๋ฒ(-ไบ้คๆณ, Euclidean algorithm) ๋๋ ์ ํด๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ์ 2๊ฐ์ ์์ฐ์ ๋๋ ์ ์(ๆดๅผ)์ ์ต๋๊ณต์ฝ์๋ฅผ ๊ตฌํ๋ ์๊ณ ๋ฆฌ์ฆ์ ํ๋์ด๋ค. ํธ์ ๋ฒ์ด๋
ko.wikipedia.org
๋ณต์ก๋ ๋ถ์
์ฃผ์ฌ์ ๋ฉด์ ์๋ฅผ n, A๊ฐ ์ด๊ธธ ํ๋ฅ ์ ๋ถ์, ๋ถ๋ชจ๋ฅผ ๊ฐ๊ฐ a, b๋ผ๊ณ ํ์.
์ด๋ ์๊ฐ ๋ณต์ก๋์ ๊ณต๊ฐ ๋ณต์ก๋๋ ์๋์ ๊ฐ๋ค.
์๊ฐ ๋ณต์ก๋ : $O(log(a + b))$
- ์ต๋๊ณต์ฝ์๋ฅผ ๊ตฌํ๊ธฐ ์ํ ์ ํด๋ฆฌ๋ ํธ์ ๋ฒ
๊ณต๊ฐ ๋ณต์ก๋ : $O(n)$
- A์ B์ ์ฃผ์ฌ์์ ๋ํ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ๋ฐฐ์ด
์ฝ๋
๋ฌธ์ ์ถ์ฒ
https://www.acmicpc.net/problem/20170
20170๋ฒ: Commemorative Dice
Since the year 2000, an ICPC regional contest has been held every year in Korea. To commemorate the 21st regional contest this year, it is decided to make a dice. The commemorative dice is a regular cube with a positive number written on each of its sides
www.acmicpc.net
'Algo Rhythm๐บ๐ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Algo Rhythm๐บ๐]BOJ 2309 - ์ผ๊ณฑ ๋์์ด (0) 2021.06.22 [Algo Rhythm๐บ๐]BOJ 14888 - ์ฐ์ฐ์ ๋ผ์๋ฃ๊ธฐ (0) 2021.06.22 [Algo Rhythm๐บ๐]BOJ 14889 - ์คํํธ์ ๋งํฌ (0) 2021.06.18 [Algo Rhythm๐บ๐]BOJ 1620 - ์ ์ ํ๋ด2 (0) 2021.03.12 [Algo Rhythm๐บ๐]BOJ 14501 - ํด์ฌ (0) 2021.03.11