본문 바로가기

분류 전체보기263

[백준] 1707번 - 이분 그래프 (파이썬) # 이분 그래프 import sys from collections import deque input = sys.stdin.readline def bfs(start): global result q = deque() q.append(start) visited[start] = 0 while q: node = q.popleft() for nnode in arr[node]: if visited[nnode] == -1: visited[nnode] = visited[node] % 2 + 1 q.append(nnode) else: if visited[nnode] == visited[node]: result = 'NO' return T = int(input()) for _ in range(T): V, E = map(in.. 2022. 1. 25.
[리액트(React)] 5. 컴포넌트(Component) - 함수 다시 처음 화면으로 돌아왔다. 이번엔 함수형 컴포넌트를 공부해보자 리액트에서 처음 함수형 컴포넌트를 사용하게 하는 목적은 단순한 정적인 화면을 쉽게 렌더링 하는 것이었다. 그래서 클래스 컴포넌트처럼 기본 기능에 state관리나 lifecyle메서드들이 없다. React 버전 16.8부터 함수형 컴포넌트도 클래스 컴포넌트처럼 사용할 수 있도록 React Hook을 새로 추가했다. 다음 장엔 React Hook을 이용해서 함수형 컴포넌트를 구현해보고 이번 장에서는 Hook 이전의 기능만 가지고 정적인 렌더링을 해보자 함수 컴포넌트 - 기본적인 함수 컴포넌트에서는 props만을 전달하는 정적인 렌더링만 가능 // App.js import React from 'react'; import './App.css' i.. 2022. 1. 24.
[백준] 2252번 - 줄 세우기 (파이썬) # 줄 세우기 from collections import deque import sys input = sys.stdin.readline N, M = map(int, input().split()) arr = [[] for _ in range(N+1)] front = [0] * (N+1) for _ in range(M): a, b = map(int, input().split()) arr[a].append(b) front[b] += 1 def sort(): result = [] q = deque() for k in range(1, len(front)): if front[k] == 0: q.append(k) while q: now = q.popleft() result.append(now) for nnow in .. 2022. 1. 24.
[백준] 1717번 - 집합의 표현 (파이썬) # 집합의 표현 import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) N, m = map(int, input().split()) parent = [i for i in range(N+1)] def union(x, y): a = find_parent(x) b = find_parent(y) if a > b: parent[a] = b else: parent[b] = a def find_parent(x): if x != parent[x]: parent[x] = find_parent(parent[x]) return parent[x] def is_set(x, y): if find_parent(x) == find_parent(y): print('YES'.. 2022. 1. 24.
[백준] 2252번 - 스도쿠 (파이썬) # 스도쿠 import sys input = sys.stdin.readline N = 9 arr = [] zero = [] for i in range(N): arr.append(list(map(int, input().split()))) for j in range(N): if arr[i][j] == 0: zero.append((i, j)) def check(x, y, num): for j in range(N): if arr[x][j] == num: return False for i in range(N): if arr[i][y] == num: return False temp_x = x // 3 * 3 temp_y = y // 3 * 3 for i in range(temp_x, temp_x+3): for j .. 2022. 1. 24.
[리액트(React)] 4. 컴포넌트(Component) - 클래스 리액트의 컴포넌트에는 클래스 컴포넌트와 함수 컴포넌트가 있다. 위 캡처본에 우측에 HOOK이라고 따로 빠져나온 게 있는데 이는 리액트 훅이라고 함수 컴포넌트를 위해 도입된 것이라서 따로 빼서 만든 것 같다. 리액트는 함수 컴포넌트를 밀고 있고, 다들 함수 컴포넌트를 사용하는 느낌이지만 기존에 이미 만들어져서 운영되고 있는 사이트들은 클래스 컴포넌트를 사용하고 있어서 둘 다 잘 알고 있어야 할 듯하다. 그래서 컴포넌트 부분만 리액트 공식문서의 순서대로가 아닌 클래스 컴포넌트 -> 함수 컴포넌트 순으로 공부를 할 예정이다! 클래스 컴포넌트 - React.Component를 상속해야 한다 // App.jsx import React, {Component} from 'react'; import './App.css.. 2022. 1. 23.
[백준] 16236번 - 아기 상어 (파이썬) # 아기 상어 import sys from collections import deque MAX = sys.maxsize input = sys.stdin.readline N = int(input()) arr = deque() fish = [] now_x = 0 now_y = 0 for i in range(N): arr.append(list(map(int, input().split()))) for j in range(N): if arr[i][j] != 0 and arr[i][j] != 9: fish.append((i, j)) elif arr[i][j] == 9: now_x = i now_y = j arr[i][j] = 0 dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] fish.sort(.. 2022. 1. 23.