Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- docker #도커 #도커 컨테이너 #docker container #도커 우분투
- 깃허브 #우분투 #ubuntu #Github #깃허브 우분투 #깃헙 우분투 #깃헙
- 구름
- 파이썬 #Python
- 구름자연어처리과정
- GPU #cuda out of memory #gpu 메모리 #pytorch
- docker #우분투 #ubuntu #도커 설치 #docker 설치 #docker installation #우분투 도커
- 알고리즘 #levenshtein distance #편집거리 #edit distance
- 머신러닝
- pandas #folium #groupby #네이버부스트코스 #코칭스터디
- ssh #우분투 ssh #우분터 서버 #도커 #우분투 도커 #docker #cuda #우분투 개발환경 #딥러닝 #ubuntu docker #ubuntu cuda
- Machine Learning
- docker #cuda #docker container #도커 #도커 컨테이너 #쿠다 #cuda 11.3
- docker #아나콘다 #anaconda #ubuntu anaconda #docker anaconda
- 트랜스포머 #transformer #attention #self-attention #어텐션 #인공지능 #AI #딥러닝 #NLP #자연어처리
- cuda #centos #cuda삭제 #리눅스 #cenos cuda삭제
- GPU #jtorch GPU #파이토치 병렬 #파이토치 GPU #pytorch gpu #multi process torch #horovod
- 백준 #알고리즘 #골드
- jupyter notebook #anaconda #vscode #pytorch #딥러닝 #deep learning #vscode server #서버 vscode #ssh vscode #vscode cuda
- pytorch #cuda #우분투 torch #ubuntu pytorch #cuda torch #cuda pytorch
- 백준
- 트랜스포머 #자연어처리 #딥러닝 #구글 #attention #self-attention #BERT #transformer #deeplearing
- BERT #구글BERT #BERT의정석
- logistic regression
Archives
- Today
- Total
바닥부터 시작하는 개발 공부
[알고리즘] 백준 1181번: 단어 정렬 본문
728x90
import sys
from collections import deque
N = int(sys.stdin.readline().strip())
words =[]
for i in range(N):
word = sys.stdin.readline().strip()
if word not in words:
words.append(word)
words_buckets =[deque() for i in range(0,50)]
while words:
word =words.pop()
words_buckets[len(word)-1].append(word)
words_buckets = [sorted(x) for x in words_buckets]
words =deque(words)
for buckets in words_buckets:
while buckets:
buckets =deque(buckets)
words.append(buckets.popleft())
for word in words:
print(word)
N개의 단어를 입력으로 받고 길이가 짧은 것을 앞에, 길이가 같다면 사전 순으로 배열함
최대 50개까지 나오므로 처음에는 input을 받으면 길이에 따라 다른 칸에 집어넣어줌(1)
그리고 각각에 칸에 대해 정렬하고(2) 앞에서부터 꺼내면 끝
시간이 걸릴만한 부분은 (1)과 (2)인데 1은 radix sort를 응용한거라 n이었을거고
(2)는 sorted 함수를 사용해서 nlogn이라 결론은 nlogn이었을것
728x90
'Algorithm > 백준' 카테고리의 다른 글
[알고리즘]백준 9012번: 괄호 (0) | 2023.01.28 |
---|---|
[알고리즘]백준 2164번: 카드2 (0) | 2023.01.28 |
[알고리즘]백준 10814번: 나이순 정렬 (0) | 2023.01.26 |
[알고리즘]백준 2751번: 수 정렬하기2 (0) | 2023.01.21 |
[알고리즘]백준 2939번: 설탕 배달 (0) | 2023.01.21 |
Comments