solved.ac: CLASS 5
Introduction
1로 만들기 2
dfs, 백트래킹
시간초과
import sys
input = sys . stdin . readline
N = int ( input ())
class dfs ():
def __init__ ( self , dp ):
self . _dp = dp
self . _min = ( 1e9 )
self . _tmp = []
self . _min_num = []
def _dfs ( self , n ):
if n == 0 :
if len ( self . _tmp ) - 1 < self . _min :
self . _min = len ( self . _tmp ) - 1
self . _min_num = self . _tmp . copy ()
return
if n % 3 == 0 :
self . _tmp . append ( n )
self . _dfs ( n // 3 )
self . _tmp . pop ()
if n % 2 == 0 :
self . _tmp . append ( n )
self . _dfs ( n // 2 )
self . _tmp . pop ()
self . _tmp . append ( n )
self . _dfs ( n - 1 )
self . _tmp . pop ()
def run ( self , n ):
self . _dfs ( n )
print ( self . _min )
print ( ' ' . join ( map ( str , self . _min_num )))
dp = []
dfs = dfs ( dp )
dfs . run ( N )
다각형의 면적
https://www.acmicpc.net/problem/2166
변의 길이가 다른 다각형의 넓이 구하기
수학
용액
이분탐색, 투포인터
최소 스패닝 트리
최소 스패닝 트리
import sys
input = sys . stdin . readline
V , E = map ( int , input (). split ())
# 부모 테이블상에서, 부모를 자기 자신으로 초기화
# -> 독립된 노드라는 의미
parent = [ 0 ] * ( V + 1 )
for i in range ( 1 , V + 1 ):
parent [ i ] = i
# 간선을 입력받아 cost를 기준으로 오름차순 정렬
edges = []
for _ in range ( E ):
A , B , C = map ( int , input (). split ())
edges . append (( C , A , B ))
edges . sort ()
## Union-Find Algorithm
# Find: 특정 원소가 속한 집합 찾기
def find_parent ( parent , x ):
if parent [ x ] != x :
parent [ x ] = find_parent ( parent , parent [ x ])
return parent [ x ]
# Union: 두 원소가 속한 집합을 합치기
def union_parent ( parent , a , b ):
a = find_parent ( parent , a )
b = find_parent ( parent , b )
if a < b :
parent [ b ] = a
else :
parent [ a ] = b
result = 0
## Kruskal Algorithm
# cost가 낮은 순으로 정렬된 간선을 하나씩 확인
for edge in edges :
cost , a , b = edge
# 두 노드의 루트 노드가 서로 다르면 사이클이 발생하지 않는다.
if find_parent ( parent , a ) != find_parent ( parent , b ):
# 신장 트리 추가 및 사이클 태이블 갱신
union_parent ( parent , a , b )
result += cost
print ( result )
도시 분할 계획
최소 스패닝 트리
두 개로 마을을 분할하므로, 연결된 스패닝 트리에서 가장 cost가 높은 값을 빼준다.
import sys
input = sys . stdin . readline
N , M = map ( int , input (). split ())
cycle_table = [ 0 ] * ( N + 1 )
for i in range ( N + 1 ):
cycle_table [ i ] = i
edges = []
for _ in range ( M ):
a , b , cost = map ( int , input (). split ())
edges . append (( cost , a , b ))
edges . sort ()
def find_parent ( parent , x ):
if parent [ x ] != x :
parent [ x ] = find_parent ( parent , parent [ x ])
return parent [ x ]
def union_parent ( parent , a , b ):
a = find_parent ( parent , a )
b = find_parent ( parent , b )
if a < b :
parent [ b ] = a
else :
parent [ a ] = b
result = 0
high_cost = 0
for edge in edges :
cost , a , b = edge
if find_parent ( cycle_table , a ) != find_parent ( cycle_table , b ):
union_parent ( cycle_table , a , b )
result += cost
if high_cost < cost :
high_cost = cost
print ( result - high_cost )
부분합
누적합, 투포인터
알파벳
깊이 우선 탐색
백트래킹
스도쿠
구현, 백트래킹
별자리 만들기
스패닝 트리
LCS 2
다이나믹
팰린드롬?
다이나믹
RGB거리 2
다이나믹
사이클 게임
자료 구조, 분리 집합
Please enable JavaScript to view the comments powered by Disqus.
2022
2 minute read
Introduction
less than 1 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
1 minute read
Introduction
1 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
1 minute read
Introduction
3 minute read
Introduction
1 minute read
Introduction
1 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Introduction
2 minute read
Introduction
less than 1 minute read
Introduction
2 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
2 minute read
Introduction
1 minute read
Introduction
3 minute read
1167 트리의 지름
3 minute read
Introduction
1 minute read
Introduction
2 minute read
Introduction
less than 1 minute read
Introduction
4 minute read
Introduction
less than 1 minute read
Introduction
6 minute read
Introduction
2 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Introduction
3 minute read
Introduction
2 minute read
Introduction
2 minute read
Introduction
3 minute read
Introduction
less than 1 minute read
Git 명령어를 사용한 하위 디렉토리 다운로드
Clone 할 로컬 저장소 생성
1 minute read
Introduction
less than 1 minute read
# Fetch the submodule commits into the main repository
git remote add submodule_origin git://url/to/submodule/origin
git fetch submodule_origin
less than 1 minute read
Introduction
less than 1 minute read
Introduction
3 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
3 minute read
Introduction
less than 1 minute read
Introduction
4 minute read
Introduction
less than 1 minute read
Introduction
less than 1 minute read
Introduction
2 minute read
Introduction
less than 1 minute read
Introduction
1 minute read
Introduction
less than 1 minute read
Spring Project
less than 1 minute read
the page for java
3 minute read
가벼운 Base image를 사용
less than 1 minute read
version: 3.0.0a10
less than 1 minute read
WIDTH
less than 1 minute read
version: 3.0.0a10
less than 1 minute read
#include <iostream>
#include <thread>
#include <chrono>
#include <mutex>
#include <atomic>
#include <string.h>
1 minute read
version: 3.0.0a10
less than 1 minute read
https://cplusplus.com/reference/future/
less than 1 minute read
Multithreading support was introduced in C++11.
less than 1 minute read
how to costom github blog using jekyll
less than 1 minute read
You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different wa...
Back to top ↑