경쟁 전문 공부 ~for Pythonista~
13429 단어 AtCoderAtCoderBeginnerContestPython3
소개
최근 AtCoder와 paiza를 시작했습니다 
가는 동안 템플릿과 같은 것이 많이 있었기 때문에,
생각해 내는 한을 비망록이 정리해 갑니다(자칭 비망록 연예인).
정리하면서 머리를 정리하겠습니다.
좋은 것이 있으면 순차적으로 갱신하자!
←를 클릭하면 복권에 갈 수 있습니다.
모쿠지
표준 입력
재귀 상한 수
재귀를 사용할 때는 염두에 써 봅시다.
재귀로 TLE
가 나올 때는 일단 써 본다.
import sys
sys.setrecursionlimit(10000)

표준 입력
다양한 형식의 입력이 지정됩니다.
한 줄만
# atcoder → 'atcoder'
S = input()
# atcoder → ['a', 't', 'c', 'o', 'd', 'e', 'r']
S = list(input())
# 1 2 3 4 → ['1', '2', '3', '4']
N = input().split()
# 1 2 3 4 → [1, 2, 3, 4]
N = list(map(int, input().split()))

여러 줄
# 2
# at
# coder
# → ['at', 'coder']
N = int(input()) # 行数
input_list = [input() for i in range(N)] # 入力行

행 수 지정 없음
사용자가 Ctrl+C
또는 <EOF>
를 입력했을 때를 종료하는 사람.
(모 회사의 웹 테스트 입력 형식이 이제 폭사했습니다
)
입력> 2021-06-05 get 100
> 2021-06-06 set 50
> 2021-06-07 get 150
> Ctrl+C
순차 처리 패턴while True:
try:
# 文字列入力の場合
input_list = list(input().split())
# 数字入力の場合
# input_list = list(map(int, input().split()))
# 逐次処理を記述
except:
# 処理ができなくなったら終了処理
break # もしくはquit(), os.exit()
목록에 추가 패턴input_list = []
while True:
try:
# 文字列入力の場合
input_list.append(list(input().split()))
# 数字入力の場合
# input_list.append(list(map(int, input().split())))
except:
# 処理ができなくなったら終了処理
break
# ~以降の処理を記述
print(input_list)
# [['2021-06-05', 'get', '100'],
# ['2021-06-06', 'set', '50'],
# ['2021-06-07', 'get', '150']]

표준 출력
print () 함수를 사용합니다.
입력 예S = 'aiueo' # str
N = 5 # int
M = 10 # int
그대로print(S) # 一般的にみるやつ
print(S, end='\n') # 上と同じ意味
# aiueo
# aiueo
후미 지정print(S, end='') # 改行しない
print(S, end=';') # 末尾に;を出力, 改行しない
# aiueoaiueo;
int와 strprint(S, N+M)
# aiueo 15
print(S+str(N+M))
# aiueo15
print(S+N+M)
# これはエラー×
# str型とint型の足し算になるため
목록의 내용을 한 글자 비우고print(' '.join([S, S, S]))
# aiueo aiueo aiueo

빈 DP 만들기
DP (Dynamic Planning Method) 문제는 빈 목록을 제공하고 결과를 저장하는 경우가 많습니다.
플래그의 관리나 탐색 알고리즘 등에 사용할 수 있을까.
N은 입력 사이즈 등# [0, 0, ..., 0, 0] 0で初期化
dp = [0 for i in range(N)]
# [[], [], ..., [], []] 空のリストのリスト
dp = [[] for i in range(N)]
#[[0, 0, ..., 0], [0, 0, ..., 0], ..., [0, 0, ..., 0]]
# 0で初期化したリストのリスト
dp = [[0 for i in range(N)] for i in range(N)]
등등 용법용량에 맞추어.

목록의 합
dp에 등록한 플래그(존재:1, 없음:0)를 세거나 할 때 사용할 수 있을 것
# 例えば
# 処理結果 dp = [0, 1, 0, 0, 1, 1, 0] 等
print(sum(dp))
# 3

목록에서 최대, 최소
# 例えば
# 処理結果 dp = [2, 1, 3, 9, 4, 8] 等
print(max(dp))
# 9
print(min(dp))
# 1

결론
초보자도 초보자입니다. 비슷한 기사도 있다고 생각합니다.
비망록이므로 용서하십시오. 왜 m...
Tips
등 있으면 꼭 가르쳐주세요!
그 중 업데이트합니다.
그럼
Reference
이 문제에 관하여(경쟁 전문 공부 ~for Pythonista~), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/RoaaaA/items/cc5947169a16914d75a0
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import sys
sys.setrecursionlimit(10000)
다양한 형식의 입력이 지정됩니다.
한 줄만
# atcoder → 'atcoder'
S = input()
# atcoder → ['a', 't', 'c', 'o', 'd', 'e', 'r']
S = list(input())
# 1 2 3 4 → ['1', '2', '3', '4']
N = input().split()
# 1 2 3 4 → [1, 2, 3, 4]
N = list(map(int, input().split()))

여러 줄
# 2
# at
# coder
# → ['at', 'coder']
N = int(input()) # 行数
input_list = [input() for i in range(N)] # 入力行

행 수 지정 없음
사용자가
Ctrl+C
또는 <EOF>
를 입력했을 때를 종료하는 사람.(모 회사의 웹 테스트 입력 형식이 이제 폭사했습니다

입력
> 2021-06-05 get 100
> 2021-06-06 set 50
> 2021-06-07 get 150
> Ctrl+C
순차 처리 패턴
while True:
try:
# 文字列入力の場合
input_list = list(input().split())
# 数字入力の場合
# input_list = list(map(int, input().split()))
# 逐次処理を記述
except:
# 処理ができなくなったら終了処理
break # もしくはquit(), os.exit()
목록에 추가 패턴
input_list = []
while True:
try:
# 文字列入力の場合
input_list.append(list(input().split()))
# 数字入力の場合
# input_list.append(list(map(int, input().split())))
except:
# 処理ができなくなったら終了処理
break
# ~以降の処理を記述
print(input_list)
# [['2021-06-05', 'get', '100'],
# ['2021-06-06', 'set', '50'],
# ['2021-06-07', 'get', '150']]

표준 출력
print () 함수를 사용합니다.
입력 예S = 'aiueo' # str
N = 5 # int
M = 10 # int
그대로print(S) # 一般的にみるやつ
print(S, end='\n') # 上と同じ意味
# aiueo
# aiueo
후미 지정print(S, end='') # 改行しない
print(S, end=';') # 末尾に;を出力, 改行しない
# aiueoaiueo;
int와 strprint(S, N+M)
# aiueo 15
print(S+str(N+M))
# aiueo15
print(S+N+M)
# これはエラー×
# str型とint型の足し算になるため
목록의 내용을 한 글자 비우고print(' '.join([S, S, S]))
# aiueo aiueo aiueo

빈 DP 만들기
DP (Dynamic Planning Method) 문제는 빈 목록을 제공하고 결과를 저장하는 경우가 많습니다.
플래그의 관리나 탐색 알고리즘 등에 사용할 수 있을까.
N은 입력 사이즈 등# [0, 0, ..., 0, 0] 0で初期化
dp = [0 for i in range(N)]
# [[], [], ..., [], []] 空のリストのリスト
dp = [[] for i in range(N)]
#[[0, 0, ..., 0], [0, 0, ..., 0], ..., [0, 0, ..., 0]]
# 0で初期化したリストのリスト
dp = [[0 for i in range(N)] for i in range(N)]
등등 용법용량에 맞추어.

목록의 합
dp에 등록한 플래그(존재:1, 없음:0)를 세거나 할 때 사용할 수 있을 것
# 例えば
# 処理結果 dp = [0, 1, 0, 0, 1, 1, 0] 等
print(sum(dp))
# 3

목록에서 최대, 최소
# 例えば
# 処理結果 dp = [2, 1, 3, 9, 4, 8] 等
print(max(dp))
# 9
print(min(dp))
# 1

결론
초보자도 초보자입니다. 비슷한 기사도 있다고 생각합니다.
비망록이므로 용서하십시오. 왜 m...
Tips
등 있으면 꼭 가르쳐주세요!
그 중 업데이트합니다.
그럼
Reference
이 문제에 관하여(경쟁 전문 공부 ~for Pythonista~), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/RoaaaA/items/cc5947169a16914d75a0
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
S = 'aiueo' # str
N = 5 # int
M = 10 # int
print(S) # 一般的にみるやつ
print(S, end='\n') # 上と同じ意味
# aiueo
# aiueo
print(S, end='') # 改行しない
print(S, end=';') # 末尾に;を出力, 改行しない
# aiueoaiueo;
print(S, N+M)
# aiueo 15
print(S+str(N+M))
# aiueo15
print(S+N+M)
# これはエラー×
# str型とint型の足し算になるため
print(' '.join([S, S, S]))
# aiueo aiueo aiueo
DP (Dynamic Planning Method) 문제는 빈 목록을 제공하고 결과를 저장하는 경우가 많습니다.
플래그의 관리나 탐색 알고리즘 등에 사용할 수 있을까.
N은 입력 사이즈 등
# [0, 0, ..., 0, 0] 0で初期化
dp = [0 for i in range(N)]
# [[], [], ..., [], []] 空のリストのリスト
dp = [[] for i in range(N)]
#[[0, 0, ..., 0], [0, 0, ..., 0], ..., [0, 0, ..., 0]]
# 0で初期化したリストのリスト
dp = [[0 for i in range(N)] for i in range(N)]
등등 용법용량에 맞추어.

목록의 합
dp에 등록한 플래그(존재:1, 없음:0)를 세거나 할 때 사용할 수 있을 것
# 例えば
# 処理結果 dp = [0, 1, 0, 0, 1, 1, 0] 等
print(sum(dp))
# 3

목록에서 최대, 최소
# 例えば
# 処理結果 dp = [2, 1, 3, 9, 4, 8] 等
print(max(dp))
# 9
print(min(dp))
# 1

결론
초보자도 초보자입니다. 비슷한 기사도 있다고 생각합니다.
비망록이므로 용서하십시오. 왜 m...
Tips
등 있으면 꼭 가르쳐주세요!
그 중 업데이트합니다.
그럼
Reference
이 문제에 관하여(경쟁 전문 공부 ~for Pythonista~), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/RoaaaA/items/cc5947169a16914d75a0
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
# 例えば
# 処理結果 dp = [0, 1, 0, 0, 1, 1, 0] 等
print(sum(dp))
# 3
# 例えば
# 処理結果 dp = [2, 1, 3, 9, 4, 8] 等
print(max(dp))
# 9
print(min(dp))
# 1

결론
초보자도 초보자입니다. 비슷한 기사도 있다고 생각합니다.
비망록이므로 용서하십시오. 왜 m...
Tips
등 있으면 꼭 가르쳐주세요!
그 중 업데이트합니다.
그럼
Reference
이 문제에 관하여(경쟁 전문 공부 ~for Pythonista~), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/RoaaaA/items/cc5947169a16914d75a0
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(경쟁 전문 공부 ~for Pythonista~), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/RoaaaA/items/cc5947169a16914d75a0텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)