반응형

전체 글 310

[백준] 1759번: 암호 만들기 (python)

www.acmicpc.net/problem/1759 1759번: 암호 만들기 첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다. www.acmicpc.net import sys from itertools import combinations def divide_alphabet(alphabet): vowel = [] consonant = [] for a in alphabet: if a in ['a', 'e', 'i', 'o', 'u']: vowel.append(a) else: consonant.append(a) return vowel, consonant def make_su..

[Dashing][CLI Tools] 5. Understanding ROS 2 services

이 글은 아래의 자료를 참고로 만들어졌습니다. docs.ros.org/en/dashing/Tutorials/Services/Understanding-ROS2-Services.html Understanding ROS 2 services — ROS 2 Documentation: Dashing documentation Goal: Learn about services in ROS 2 using command line tools. Nodes can communicate using services in ROS 2. Services only pass information to a node if that node specifically requests it, and will only do so once per requ..

[백준] 11279번: 최대 힙 (python)

www.acmicpc.net/problem/11279 11279번: 최대 힙 첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 www.acmicpc.net import sys def swap(a,b): tmp = a a = b b = tmp return a, b def insert_max_heap(heap, x): child = len(heap) heap.append(x) while(True): parent = child//2 if heap[parent] < heap[child]: heap[parent], heap[child] = swap(he..

[Dashing][CLI Tools] 4. Understanding ROS 2 topics

이 글은 아래의 자료를 참고로 만들어졌습니다. docs.ros.org/en/dashing/Tutorials/Topics/Understanding-ROS2-Topics.html Understanding ROS 2 topics — ROS 2 Documentation: Dashing documentation You're reading the documentation for an older, but still supported, version of ROS 2. For information on the latest version, please have a look at Foxy. Understanding ROS 2 topics Goal: Use rqt_graph and command line tools to in..

[Dashing][CLI Tools] 3. Understanding ROS 2 nodes

이 글은 아래의 자료를 참고로 만들어졌습니다. docs.ros.org/en/dashing/Tutorials/Understanding-ROS2-Nodes.html Understanding ROS 2 nodes — ROS 2 Documentation: Dashing documentation ros2 node list will show you the names of all running nodes. This is especially useful when you want to interact with a node, or when you have a system running many nodes and need to keep track of them. Open a new terminal while turtlesi..

[엔진 진동 저감 설계] 1. 데이터 해석과 FFT

엔진 진동 데이터 해석과 FFT 이번 내용은 기계진동학에서 배운 내용을 실제 자동차 엔진에 적용해보겠습니다. 1. 목표 주어진 데이터를 해석하고, 시스템에 알맞은 스프링과 뎀퍼 설정하기 1) 주어진 데이터를 FFT를 이용하여 해석하고 단순화하기 2) 자동차 엔진에서 발생하는 진동을 적절한 스프링과 뎀퍼로 저감 3) 차체에 전달되는 진동에 의한 외력을 감소 2. 데이터 분석 (MATLAB) 무게가 250kg인 자동차 엔진의 전체 진동 데이터는 다음과 같습니다. 시간에 대하여 확대한 그림은 다음과 같습니다. 3. FFT (Fast Fourier Transform) 위와 같은 진동에 대하여 FFT를 이용하여 주파수를 분석합니다. 복소 푸리에 계수는 다음과 같습니다. MATLAB의 FFT 첫번째 결과는 데이터의..

[백준] 2143번: 두 배열의 합 (python)

www.acmicpc.net/problem/2143 2143번: 두 배열의 합 첫째 줄에 T(-1,000,000,000 ≤ T ≤ 1,000,000,000)가 주어진다. 다음 줄에는 n(1 ≤ n ≤ 1,000)이 주어지고, 그 다음 줄에 n개의 정수로 A[1], …, A[n]이 주어진다. 다음 줄에는 m(1≤m≤1,000)이 주어지고, 그 다 www.acmicpc.net import sys def find_sum_dic(num, array): sum_dic = {} for i in range(num): for j in range(i+1,num+1): s = sum(array[i:j]) if s in sum_dic: sum_dic[s] += 1 else: sum_dic[s] = 1 return sum_d..

[백준] 2003번: 수들의 합 2 (python)

www.acmicpc.net/problem/2003 2003번: 수들의 합 2 첫째 줄에 N(1 ≤ N ≤ 10,000), M(1 ≤ M ≤ 300,000,000)이 주어진다. 다음 줄에는 A[1], A[2], …, A[N]이 공백으로 분리되어 주어진다. 각각의 A[x]는 30,000을 넘지 않는 자연수이다. www.acmicpc.net import sys N, M = map(int,sys.stdin.readline().split()) A = list(map(int,sys.stdin.readline().split())) num = 0 idx = 0 q = [] while(idx = N: break q.append(A[idx]) idx += 1 elif sum(q) >= M: if sum(q) == M: ..

[Dashing][CLI Tools] 2. Introducing turtlesim and rqt

이 글은 아래의 자료를 참고로 만들어졌습니다. docs.ros.org/en/dashing/Tutorials/Turtlesim/Introducing-Turtlesim.html Introducing turtlesim and rqt — ROS 2 Documentation: Dashing documentation Open a new terminal and source ROS 2 again. At this point you should have three windows open: a terminal running turtlesim_node, a terminal running turtle_teleop_key and the turtlesim window. Arrange these windows so that you ..

[백준] 2096번: 내려가기 (python)

www.acmicpc.net/problem/2096 2096번: 내려가기 첫째 줄에 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 숫자가 세 개씩 주어진다. 숫자는 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 중의 하나가 된다. www.acmicpc.net import sys def use_dp(fun, dp): x1 = board_r[0] + fun(dp[:2]) x2 = board_r[1] + fun(dp) x3 = board_r[2] + fun(dp[1:]) return [x1, x2, x3] if __name__ == '__main__': N = int(sys.stdin.readline()) max_dp = [0]*3 min_dp = [0]*3 for r in range..

[백준] 2748번: 피보나치 수 2 (python)

www.acmicpc.net/problem/2748 2748번: 피보나치 수 2 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가 www.acmicpc.net def iter(n, cache): if n < 2: cache[n] = n return cache[n] if cache[n] != -1: return cache[n] cache[n] = iter(n-1, cache) + iter(n-2, cache) return cache[n] def fibonacci(n): cache = [-1 for _ in range(n+1)] ret..

[백준] 1339번: 단어수학 (python)

www.acmicpc.net/problem/1339 1339번: 단어 수학 첫째 줄에 단어의 개수 N(1 ≤ N ≤ 10)이 주어진다. 둘째 줄부터 N개의 줄에 단어가 한 줄에 하나씩 주어진다. 단어는 알파벳 대문자로만 이루어져있다. 모든 단어에 포함되어 있는 알파벳은 최대 www.acmicpc.net def make_score(N, word): score = {} for i in range(N): for j, e in enumerate(word[i]): s = 10**(len(word[i])-j-1) if not e in score: score[e] = s else: score[e] += s return score def cal_max(score): sorted_score = sorted(list(sc..

[백준] 3055번: 탈출 (python)

www.acmicpc.net/problem/3055 3055번: 탈출 사악한 암흑의 군주 이민혁은 드디어 마법 구슬을 손에 넣었고, 그 능력을 실험해보기 위해 근처의 티떱숲에 홍수를 일으키려고 한다. 이 숲에는 고슴도치가 한 마리 살고 있다. 고슴도치는 제 www.acmicpc.net import sys def find_loc(R,C,chart,e='S'): loc = [] for r in range(R): for c in range(C): if chart[r][c] == e: loc.append([r,c]) return loc def move_position(R,C,chart,s_loc): expand = [] goal = False for l in s_loc: lr,lc = l near = [[lr,..

[백준] 1103번: 게임 (python)

www.acmicpc.net/problem/1103 1103번: 게임 줄에 보드의 세로 크기 N과 가로 크기 M이 주어진다. 이 값은 모두 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 보드의 상태가 주어진다. 쓰여 있는 숫자는 1부터 9까지의 자연수 또는 www.acmicpc.net import sys sys.setrecursionlimit(10**6) dr = [0, 1, 0,-1] dc = [1, 0,-1, 0] def dfs(r ,c): global state, visited if not(0

[백준] 1713번: 후보 추천하기 (python)

www.acmicpc.net/problem/1713 1713번: 후보 추천하기 첫째 줄에는 사진틀의 개수 N이 주어진다. (1≤N≤20) 둘째 줄에는 전체 학생의 총 추천 횟수가 주어지고, 셋째 줄에는 추천받은 학생을 나타내는 번호가 빈 칸을 사이에 두고 추천받은 순서대로 www.acmicpc.net import sys n = int(input()) num_student = int(input()) vote = list(map(int,sys.stdin.readline().split())) fig = [] num_fig = [] for v in vote: if v in fig: idx = fig.index(v) num_fig[idx] += 1 else: if len(fig) >= n: idx = num_fi..

[백준] 15686번: 치킨 배달 (python)

www.acmicpc.net/problem/15686 15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net import sys import itertools def find_location(city, N): home = [] chicken = [] for r in range(N): for c in range(N): if city[r][c] == 1: home.append([r,c]) elif city[r][c] == 2: chicken.append([r,c]) return home, chicke..

[백준] 1920번: 수찾기 (python)

www.acmicpc.net/problem/1920 1920번: 수 찾기 첫째 줄에 자연수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 N개의 정수 A[1], A[2], …, A[N]이 주어진다. 다음 줄에는 M(1 ≤ M ≤ 100,000)이 주어진다. 다음 줄에는 M개의 수들이 주어지는데, 이 수들 www.acmicpc.net import sys def binary_search(find_list, item, start, end): if start > end: print(0) else: mid = int((start+end)/2) if item == find_list[mid]: print(1) elif item < find_list[mid]: end = mid -1 return binar..

[Dashing][CLI Tools] 1. Configuring your ROS 2 environment

이 글은 아래의 자료를 참고로 만들어졌습니다. docs.ros.org/en/dashing/Tutorials/Configuring-ROS2-Environment.html Configuring your ROS 2 environment — ROS 2 Documentation: Dashing documentation Sourcing ROS 2 setup files will set several environment variables necessary for operating ROS 2. If you ever have problems finding or using your ROS 2 packages, make sure that your environment is properly setup using the fol..

[Linux] Terminator (터미널 다중 창, 창분할)

Linux를 쓰다보면 여러 Terminal에 명령어를 쓸 경우가 있습니다. 이를 편리하게 도와주는 Terminator에 대해 알아봅시다. 1. 설치 $ sudo apt install terminator 2. 창 분할 실행시킨 Terminator에 마우스 오른쪽 클릭을 하면 아래와 같은 팝업이 뜨며, Split Horizontally, Split Vertically를 이용하여 창을 분할할 수 있습니다. 3. Layouts 설정 터미널을 새로 실행시킬 때, 설정한 Layout으로 바로 실행시키는 방법이 있습니다. config파일을 만들어서 실행하는 방법도 있지만, 그보다 사용하기 간단한 방법을 소개합니다. 1) 원하는 Layout 만들기 2) Preferences 클릭 3) Layouts에서 default에..

Development/Linux 2021.05.03
반응형