μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- mongodb
- 그리λ
- javascript
- νλ‘ νΈμλ
- μ½λ©ν μ€νΈ
- μ½λ©
- HTML
- μ½λ©μ ν
- νμ΄μ¬
- fe
- error
- KDT
- heapq
- νλ‘κ·Έλλ¨Έμ€
- Til
- Python
- JS
- μκ³ λ¦¬μ¦
- κ°λ°
- CSS
- ν¬λ‘€λ§
- νλ‘μ νΈ
- λͺ¨κ°μ½
- react
- node.js
- λλ¦Όμ½λ©
- κ΅λΉμ§μ
- λ Έλ§λμ½λ
- λ°±μ€
- ν μ΄νλ‘μ νΈ
- Today
- Total
π± β π³
[λ°±μ€] 2108λ²: ν΅κ³ν python λ³Έλ¬Έ
https://www.acmicpc.net/problem/2108
2108λ²: ν΅κ³ν
첫째 μ€μ μμ κ°μ N(1 β€ N β€ 500,000)μ΄ μ£Όμ΄μ§λ€. λ¨, Nμ νμμ΄λ€. κ·Έ λ€μ Nκ°μ μ€μλ μ μλ€μ΄ μ£Όμ΄μ§λ€. μ λ ₯λλ μ μμ μ λκ°μ 4,000μ λμ§ μλλ€.
www.acmicpc.net
μ λ΅μ½λ:
from collections import Counter
import sys
a = int(sys.stdin.readline())
b= []
for i in range(a):
b.append(int(sys.stdin.readline()))
b.sort()
c = a//2
# μ°μ νκ·
print(round(sum(b)/a))
# μ€μκ°
print(b[c])
# μ΅λΉκ°
cnt = Counter(b).most_common(2)
if len(b)>1 and cnt[0][1] == cnt[1][1]:
print(cnt[1][0])
else:
print(cnt[0][0])
# μ΅λκ° - μ΅μκ°
print(b[a-1]-b[0])
λλ¨Έμ§λ κ·Έλμ λ ν λ§ νκ³
μ΅λΉλκ° κ°μ₯ λ¬Έμ μλλ° count()ν¨μλ₯Ό μ¬μ©νλ©΄ μκ°μ΄κ³Όκ° λ μ λ€λ₯Έ λ°©λ²μ μκ°ν΄μΌ νλ€
κ²μν΄λ³΄λ collectionμ Counterλ₯Ό νμ©νμ¬ λΉλμλ₯Ό ꡬνλ κ²μ νμΈν μ μμλ€
Counter(b)λ₯Ό νλ©΄ dict ννλ‘ μΆλ ₯λκΈ° λλ¬Έμ .most_common()ν¨μλ₯Ό 리μ€νΈμ λ΄κΈ΄ νν ννλ‘ μμλ€μ λΉλλ₯Ό ꡬνλ€
5κ°μ μ 1,3,8,-1,2λ₯Ό μ λ ₯ν κ²½μ° counter()μ counter().most_common()μ μλμ κ°λ€
print("Counter(b) = " ,Counter(b))
print("Counter(b).most_common(2) =" , Counter(b).most_common())

most_common()μ ν΅ν΄ λ§λ€μ΄μ§ ννμ (μμ, λΉλμ) ννλ‘ λΉλμκ° λ§μ μλΆν° μμμ μμλλ‘ μ μ₯λμ΄ μκ³ , κ°μ λΉλμλΌλ©΄ μ²μ λμ¨ κ°μ΄ μμ μμΉνλ€.
μ½λλ₯Ό μμ±ν λ b.sort()λ‘ μ λ ¬ν΄μ€¬κΈ° λλ¬Έμ
μ΅λΉκ° μ€ μ΅μκ°: count[0][0]
μ΅λΉκ° μ€ λλ²μ§Έλ‘ μμ κ°: count[1][0]
μμ νμΈν μ μλ€
μ°Έκ³ ν λΈλ‘κ·Έ
https://joylee-developer.tistory.com/94
(νμ΄μ¬) λ°±μ€ μκ³ λ¦¬μ¦ - 2108λ² / Counter
ν΅κ³ν https://www.acmicpc.net/problem/2108 2108λ²: ν΅κ³ν 첫째 μ€μ μμ κ°μ N(1 β€ N β€ 500,000)μ΄ μ£Όμ΄μ§λ€. λ¨, Nμ νμμ΄λ€. κ·Έ λ€μ Nκ°μ μ€μλ μ μλ€μ΄ μ£Όμ΄μ§λ€. μ λ ₯λλ μ μμ μ λκ°μ 4,0..
joylee-developer.tistory.com
'Algorithms' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Algorithm) μκ³ λ¦¬μ¦ μ±λ₯ (0) | 2022.10.25 |
---|---|
[λ°±μ€] 18870λ²: μ’ν μμΆ python (0) | 2022.10.10 |
[λ°±μ€] 10989λ²: μ μ λ ¬νκΈ° 3 python (0) | 2022.10.02 |
[λ°±μ€] 2750, 2751 - μ μ λ ¬νκΈ° 1,2 python (0) | 2022.10.02 |
[λ°±μ€] 9020λ²: 골λλ°νμ μΆμΈ‘ (0) | 2022.07.30 |