์ ์ฒด ๊ธ
-
[Python] ๋ฐฑ์ค 11650 - ์ขํ ์ ๋ ฌํ๊ธฐAlgorithm/๋ฐฑ์ค 2021. 10. 12. 20:45
1. ๋ฌธ์ ๐ https://www.acmicpc.net/problem/11650 11650๋ฒ: ์ขํ ์ ๋ ฌํ๊ธฐ ์ฒซ์งธ ์ค์ ์ ์ ๊ฐ์ N (1 ≤ N ≤ 100,000)์ด ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์๋ i๋ฒ์ ์ ์์น xi์ yi๊ฐ ์ฃผ์ด์ง๋ค. (-100,000 ≤ xi, yi ≤ 100,000) ์ขํ๋ ํญ์ ์ ์์ด๊ณ , ์์น๊ฐ ๊ฐ์ ๋ ์ ์ ์๋ค. www.acmicpc.net 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ sorted ํจ์๋ฅผ ์ด์ฉํ์ฌ ์ ๋ ฌํ๋ค. โ๏ธ list๋ฅผ sort ํ ๊ฒฝ์ฐ๋ ๋งจ ์์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํ๋ค. 4. ์์ค์ฝ๋ ๐ป import sys input = sys.stdin.readline N = int(input()) nums = [] for i in range(N): [a, b] = map..
-
[Python] ์ ๊ตญ์ฌ์ฌAlgorithm/ํ๋ก๊ทธ๋๋จธ์ค 2021. 6. 3. 02:52
1. ๋ฌธ์ ๐ 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ์ฝํ ์ ์ด์ง ํ์ ๋ฌธ์ ๋ ํ์๋ฒ์๊ฐ ํฐ ์ํฉ์์ ํ์์ ๊ฐ์ ํ๋ ๋ฌธ์ ๊ฐ ๋ง๋ค. ๋ฐ๋ผ์ ํ์ ๋ฒ์๊ฐ ํด ๊ฒฝ์ฐ ์ด์ง ํ์์ผ๋ก ๋ฌธ์ ์ ์ ๊ทผํด๋ณด์ ! 1. ์ผ์ ํ๋ ๋ฐ ์์ํ๋ ์๊ฐ min, max ์ ํ๊ธฐ min = 1 max = ๊ฐ์ฅ ์ค๋ ๊ฑธ๋ฆฌ๋ ์ฌ์ฌ๋ * ์ผ์ ๊ฐ์ 2. ๊ฐ ์ ๊ตญ ์ฌ์ฌ๋์์ ์ฒ๋ฆฌ ํ ์ผ๋ค์ด n์ ๊ฐ์ด ๋๋ ์ง ํ์ธํด๋ณด๊ธฐ ๊ฐ ์ ๊ตญ ์ฌ์ฌ๋์์ ์ผํ ๊ฐ์ = mid // n 3. mid ๊ฐ ์กฐ์ ํ๊ธฐ - mid / time ์ด n์ ๊ฐ๋ณด๋ค ํฌ๋ค๋ฉด, mid๋ฅผ ์ค์ธ๋ค. - mid / time ์ด n์ ๊ฐ๋ณด๋ค ์๋ค๋ฉด, mid๋ฅผ ๋๋ฆฐ๋ค. ๋ง์ง๋ง mid ๊ฐ์ด ์ฐ๋ฆฌ๊ฐ ๊ตฌํ๋ ์ต์ ๊ฐ์ด ๋๋ค. 4. ์์ค์ฝ๋ ๐ป def solution(n, times): st..
-
[Python] ๋ฐฑ์ค 2193๋ฒ ์ด์น์Algorithm/๋ฐฑ์ค 2021. 5. 17. 23:59
1. ๋ฌธ์ ๐ 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ Dp ๋ฌธ์ ์ด๋ฏ๋ก ๊ท์น ๋๋ ์ ํ์์ ์ฐพ๋๋ค N / ๋์ ์ 0 1 ์ถ๋ ฅ ๊ฐ(๊ฐฏ์) 1 0 1 1 2 1 0 1 3 1 1 2 4 2 1 3 5 3 2 5 6 5 3 8 ๊ท์น์ ๋ณด๋ฉด, N์ด 1๊ณผ, 2์ผ ๋ 1์ด๋ฉฐ ๊ทธ ์ด์ธ์ ๊ทธ ์ ์ ๊ฐ 2๊ฐ๋ฅผ ํฉ์น ๊ฐ๊ณผ ์ถ๋ ฅ ๊ฐ์ด ๊ฐ๋ค๋ ๊ท์น์ ์ฐพ์ ์ ์๋ค. 4. ์์ค์ฝ๋ ๐ป n = int(input()) nums = [1] * n if n == 1 or n == 2: print(1) else: for i in range(2, n): nums[i] = nums[i-1] + nums[i-2] print(nums[n-1])
-
[Python] ๋ฐฑ์ค 2439๋ฒ ๋ณ์ฐ๊ธฐ - 2Algorithm/๋ฐฑ์ค 2021. 5. 8. 22:37
1. ๋ฌธ์ ๐ 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ 1~n๊น์ง *์ ์ถ๋ ฅ์ํค๊ณ , ๋์ด์ฐ๊ธฐ๋ n-i๋งํผ ' '์ ์ถ๋ ฅ์ํจ๋ค 4. ์์ค์ฝ๋ ๐ป n = int(input()) for i in range(1, n+1): print(' ' * (n - i) + '*' * i)
-
[Python] ๋ฐฑ์ค 2438๋ฒ ๋ณ์ฐ๊ธฐAlgorithm/๋ฐฑ์ค 2021. 5. 8. 22:00
1. ๋ฌธ์ ๐ / ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ i ๋ฒ์ ๋ฐ๊ณ i๋ฒ์ ๋ฐ๋ณตํ์ฌ ๋ณ์ ์ฐ๋๋ค 4. ์์ค์ฝ๋ ๐ป [๋ด๊ฐ ์ด ์ฝ๋] n = int(input()) for i in range(1, n+1): while i != 0: print('*', end = '') i -= 1 print() [ํ์ด์ฌ ๋ค์ด ์ฝ๋] n = int(input()) for i in range(1, n+1): print('*' * i) ํ์ด์ฌ์ string๋ ๊ณฑํ๊ธฐ๊ฐ ๋๋ค๋ ๊ฒ์ ๊ธฐ์ตํ์โ๏ธโ๏ธ
-
[Python] ๋ก๋์ ์ต๊ณ ์์์ ์ต์ ์์Algorithm/ํ๋ก๊ทธ๋๋จธ์ค 2021. 5. 5. 23:54
1. ๋ฌธ์ ๐ 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ wins_num์๋ ๊ฐ์ ์ซ์๊ฐ ๋ด๊ฒจ์์ง ์์ผ๋ฏ๋ก, 0์ด ๋ชจ๋ ๋ง์ผ๋ฉด, ์ต๊ณ ์์๊ฐ ๋๋ค ์ต์ ์์๋ 0์ด ๋ชจ๋ ์๋ง๊ณ , win_nums๊ณผ ๊ฐ์ ์ซ์์ ๊ฐฏ์๊ฐ ์ต์ ๊ฐ์๊ฐ ๋๋ค. 2๊ฐ๊ฐ ์ผ์นํ๋ ๊ฒ๋ถํฐ ์์๋ฅผ ์ฃผ๊ณ , ๋๋จธ์ง๋ 6์์ด๋ฏ๋ก index๋ฅผ ๋ง์ ๊ฐฏ์๋ก ์๊ฐํ๊ณ ๋ฆฌ์คํธ๋ฅผ ๋ง๋ค์ด ์ค๋ค ๋ฐ๋ผ์ ์ต๊ณ ์์ = ์ผ์นํ๋ ๋ฒํธ ๊ฐฏ์ + 0์ ๊ฐฏ์ ์ต์ ์์ = ์ผ์นํ๋ ๋ฒํธ ๊ฐฏ์ 4. ์์ค์ฝ๋ ๐ป def solution(lottos, win_nums): answer = 0 rank = [6, 6, 5, 4, 3, 2, 1] cnt_0 = lottos.count(0) for num in win_nums: if num in lottos: answer += 1 ..
-
[Python] ํฐ์ผ๋ชฌAlgorithm/ํ๋ก๊ทธ๋๋จธ์ค 2021. 5. 3. 23:21
1. ๋ฌธ์ ๐ 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ๊ฐ์ฅ ๋ง์ ์ข ๋ฅ์ ํฐ์ผ๋ชฌ์ ๊ฐ๊ณ ์ถ์ดํ๊ธฐ ๋๋ฌธ์ ๋ฐ์ฌ๋์ด ๊ฐ์ง๊ณ ์๋ ํฐ์ผ๋ชฌ /2 ๋งํผ ์ค๋ณต์ ๊ฑฐ๋ฅผ ํด์ค๋ค 4. ์์ค์ฝ๋ ๐ป def solution(nums): count=len(nums)//2 poketmon = [] for i in nums: if poketmon.count(i) == 0: poketmon.append(i) return len(poketmon[:count]) 5. ๋ค๋ฅธ์ฌ๋์ ํ์ด ๐ป def solution(nums): return min(len(nums)/2, len(set(nums))) ์์ผ๋ก๋ if ์ ๋ก ์ค๋ณต์ ์ ๊ฑฐํ๋ ๋ฐฉ๋ฒ๋ณด๋จ set์ ์ด์ฉํ์! ๐