백준 1527 파이썬
(1) 처음 내 코드 -> 시간초과 a,b = map(int,input().split()) cnt = 0 s1="4" s2="7" for i in range(a,b+1): s = str(i) bool=True for j in s: if j==s1 or j==s2: continue else: bool=False break if bool==True: cnt+=1 print(cnt) 입력이 1보다 크고, 1,000,000,000보다 작거나 같은 자연수로, 코드 제출하기 버튼을 누르면서도 뭔가 시간초과가 날거 같았다. (2) 문제 해결 후 내 코드 -> product 사용 from itertools import product a,b = map(int,input().split()) cnt = 0 key = [] ..
2023. 1. 25.
[백준] 2178번 : 미로 탐색 (파이썬)
미로탐색 문제로, dfs나 bfs로 푸는 문제이다. 나는 bfs를 이용하여 문제를 해결하였다. 처음 내 코드 from collections import deque a,b = map(int,input().split()) visit = [[0]*b for _ in range(a)] for i in range(a): c = input() for j in range(b): visit[i][j] = int(c[j]) print(visit) #BFS queue = deque() dx = [-1,1,0,0] dy = [0,0,-1,1] length=0 for i in range(a): for j in range(b): if visit[i][j]==1: visit[i][j]=0 queue.append([i,j]) le..
2023. 1. 23.
[백준] 2583번 : 영역 구하기 (파이썬)
import sys from collections import deque a,b,c = map(int,input().split()) visit = [[0]*b for _ in range(a)] dx=[0,0,1,-1] dy=[1,-1,0,0] # visit = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] for i in range(c): x1,y1,x2,y2 = map(int,input().split()) for i in range(y1,y2,1): for j in range(x1,x2,1): visit[i][j]=1 queue = deque(..
2023. 1. 22.