๋ฐ์ํ
๐ค๋ฌธ์ ํด๊ฒฐ
-
D3
๐จ ๋๋ฒ์งธ ์ฆ๊ฑฐ์ด ๋ ๋ถํฐ 1์ผ๊ณผ์ ์ฐจ์ด๋ฅผ ๊ณ์ฐํ๋ค
๐จ ๊ทธ ๊ท์น๋งํผ ๋ง์ง๋ง ์ฆ๊ฑฐ์ด ๋ ๊น์ง์ ๋ฐฐ๋ฅผ ๋ฐฐ์ด์ ๋ด๋๋ค.
๐จ ๋ค์ ์ฆ๊ฑฐ์ด ๋ ์ด ์ด๋ฏธ ๋ฐฐ์ด์ ์๋ ๊ฒฝ์ฐ๋ง ์ฐจ์ด๋ฅผ ๊ณ์ฐํ์ฌ ๋ฐ๋ณตํ๋ค.
๐จ 1, 7, 10, 13, 19
๐จ ๋๋ฒ์งธ ์ฆ๊ฑฐ์ด ๋ (7) ๊ณผ 1์ผ ์ฐจ์ด = 6
๐จ ๋ฐฐ์ด = [7, 13, 19]
๐จ ์ธ๋ฒ์งธ ์ฆ๊ฑฐ์ด๋ 10 ์ ๋ฐฐ์ด์ ์์ผ๋ฏ๋ก ์ฐจ์ด ๊ณ์ฐ
๐จ ์ธ๋ฒ์ฌ ์ฆ๊ฑฐ์ด ๋ (10) ๊ณผ 1์ผ ์ฐจ์ด = 9
๐จ ๋ฐฐ์ด = [7, 10, 13, 19]
๐จ ๋ค๋ฒ์งธ, ๋ค์ฏ๋ฒ์งธ ์ฆ๊ฑฐ์ด ๋ (13, 19) ๋ ์ด๋ฏธ ๋ฐฐ์ด์ ์์ผ๋ฏ๋ก pass
๐จ ์ด ๊ณ์ฐ์ ๋ ๋ฒ ํ์ผ๋ฏ๋ก ๋ฐฐ๋ 2๊ฐ
๐ป์์ค ์ฝ๋
for tc in range(int(input())):
N = int(input())
happy_days = []
for i in range(N):
happy_days.append(int(input()))
ships = set()
answer = 0
for i in range(1, len(happy_days)):
if happy_days[i] in ships:
continue
gap = happy_days[i] - 1
for j in range(1 + gap, happy_days[-1] + 1, gap):
ships.add(j)
answer += 1
print(f'#{tc + 1} {answer}')
๐๋ฌธ์ ํ์ธ
์ถ์ฒ: SW Expert Academy
๋ฐ์ํ
'Algorithm Problem > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[python] SWEA - 3282. 0/1 Knapsack (0) | 2020.12.17 |
---|---|
[python] SWEA - 3975. ์น๋ฅ ๋น๊ตํ๊ธฐ (0) | 2020.12.16 |
[python] SWEA - 4579. ์ธ์์ ๋ชจ๋ ํฐ๋ฆฐ๋๋กฌ 2 (0) | 2020.12.14 |
[python] SWEA - 4698. ํ ๋ค์ค์ ํน๋ณํ ์์ (0) | 2020.12.13 |
[python] SWEA - 4751. ๋ค์์ด์ ๋ค์ด์๋ชฌ๋ ์ฅ์ (0) | 2020.12.12 |