diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Algorithms_Study.iml b/.idea/Algorithms_Study.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/.idea/Algorithms_Study.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ae4dcfc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CJW/1021.py b/CJW/1021.py new file mode 100644 index 0000000..af7156d --- /dev/null +++ b/CJW/1021.py @@ -0,0 +1,51 @@ +from collections import deque +import sys + +dq = deque() +N,M = map(int,sys.stdin.readline().split()) +dq.extend([i for i in range(1,N+1)]) + +target_list = list(map(int,input().split())) + +cnt=0 +while target_list: + right_cnt=0 + left_cnt=0 + + while target_list[0] != dq[0]: + dq.rotate(1) + right_cnt+=1 + dq.rotate(-right_cnt) + + while target_list[0] != dq[0]: + dq.rotate(-1) + left_cnt+=1 + + if right_cnt < left_cnt: + dq.rotate(left_cnt+right_cnt) + cnt+=min(right_cnt, left_cnt) + dq.remove(target_list[0]) + target_list.pop(0) + +print(cnt) + + +''' +1) 리스트 내포 +#1 a,b,c,d = [int(x) for x in input().split()] +#2 a,b,c,d = map(int,input().split()) +#3 a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()] +stdout.write(str(a*b*c*d)) +''' + +''' +2) List가 empty인지 확인 +list1 = [] +list2 = [1,2,3] + +if not list1: + print("list1 is empty") #list1 is empty +if list2: + print("list2 is not empty") #list2 is not empty + +''' \ No newline at end of file diff --git a/CJW/1085.py b/CJW/1085.py new file mode 100644 index 0000000..e5e4f36 --- /dev/null +++ b/CJW/1085.py @@ -0,0 +1,9 @@ +x,y,w,h = map(int, input().split()) + +w-=x +h-=y +if(w>=x): + w=x +if(h>=y): + h=y +print(min(w,h)) \ No newline at end of file diff --git a/CJW/1181.py b/CJW/1181.py new file mode 100644 index 0000000..fd05a97 --- /dev/null +++ b/CJW/1181.py @@ -0,0 +1,8 @@ +import sys + +n=int(sys.stdin.readline()) +my_list = [sys.stdin.readline().strip() for i in range(n)] + +my_list.sort() +my_list.sort(key=lambda i:len(i)) +print(my_list) \ No newline at end of file diff --git a/CJW/14244.py b/CJW/14244.py new file mode 100644 index 0000000..86397ea --- /dev/null +++ b/CJW/14244.py @@ -0,0 +1,12 @@ +n,m = map(int,input().split()) + +if m == 2: + for i in range(n - 1): + print(i, i + 1) + +else: + print("0 1") + for i in range(2, m + 1): + print(1, i) + for j in range(m, n - 1): + print(j, j + 1) \ No newline at end of file diff --git a/CJW/2346.py b/CJW/2346.py new file mode 100644 index 0000000..f3799e2 --- /dev/null +++ b/CJW/2346.py @@ -0,0 +1,18 @@ +from collections import deque +import sys + +N = int(sys.stdin.readline()) +dq = deque(map(int, input().split())) +ballon_list = [] + +dq_game = dq.copy() +while dq_game: + target = dq_game[0] + print(target) + dq_game.rotate(-target) + ballon_list.append((dq_game.index(target))+1) + dq_game.remove(target) + print(dq_game) + +print(*ballon_list) + diff --git a/CJW/9372.py b/CJW/9372.py new file mode 100644 index 0000000..f7a92f3 --- /dev/null +++ b/CJW/9372.py @@ -0,0 +1,39 @@ +from collections import deque + +t = int(input()) + +def bfs(start, cnt_plane): + dq= deque() + dq.append(start) + visited[start] = True + + while dq: + if visited.count(True) == n : + return cnt_plane + + current_node = dq.popleft() + + for node in graph[current_node]: + if visited[node]==False : + dq.append(node) + visited[node] = True + cnt_plane +=1 + + + +for i in range(t): + #국가의 수n 비행기의 종류 m + n, m = map(int,input().split()) + visited = [False]*(n+1) + + graph = [[] for i in range(n+1)] + + for j in range(m): + x,y = map(int,input().split()) + graph[x].append(y) + graph[y].append(x) + + print(bfs(1,0)) + + + diff --git a/CJW/BinaryTree/.idea/.gitignore b/CJW/BinaryTree/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/CJW/BinaryTree/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/CJW/BinaryTree/.idea/misc.xml b/CJW/BinaryTree/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/CJW/BinaryTree/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CJW/BinaryTree/.idea/modules.xml b/CJW/BinaryTree/.idea/modules.xml new file mode 100644 index 0000000..fd6712a --- /dev/null +++ b/CJW/BinaryTree/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CJW/BinaryTree/.idea/uiDesigner.xml b/CJW/BinaryTree/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/CJW/BinaryTree/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CJW/BinaryTree/BinaryTree.iml b/CJW/BinaryTree/BinaryTree.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/CJW/BinaryTree/BinaryTree.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/CJW/BinaryTree/src/BinaryTree.java b/CJW/BinaryTree/src/BinaryTree.java new file mode 100644 index 0000000..fe7b1bf --- /dev/null +++ b/CJW/BinaryTree/src/BinaryTree.java @@ -0,0 +1,84 @@ +class Node { + int data; + Node leftChild; + Node rightChild; + + public Node(int data) { + this.data = data; + this.leftChild = this.rightChild = null; + } +} + + +public class BinaryTree { + + public Node insertNode(Node root, int data) { + if(root == null) { + return new Node(data); + } + + if(data < root.data) { + root.leftChild = insertNode(root.leftChild, data); + } + else { + root.rightChild = insertNode(root.rightChild, data); + } + return root; + } + + public Node searchNode(Node root, int searchtarget) { + if(root == null) { + return null; + } + + if(root.data == searchtarget){ + return root; + } + else if(searchtarget < root.data){ + return searchNode(root.leftChild, searchtarget); + } + else { + return searchNode(root.rightChild, searchtarget); + } + } + + public Node deleteNode(Node root, int deletetarget) { + if(root == null) { + return null; + } + + if(deletetarget < root.data) { + root.leftChild = deleteNode(root.leftChild, deletetarget); + } + else if(deletetarget > root.data) { + root.rightChild = deleteNode(root.rightChild, deletetarget); + } + return root; + } + + //전위순회 + public void preorder(Node currentNode) { + if(currentNode != null) { + System.out.println(currentNode.data + " "); + preorder(currentNode.leftChild); + preorder(currentNode.rightChild); + } + } + //중위순회 + public void inorder(Node currentNode) { + if(currentNode != null) { + inorder(currentNode.leftChild); + System.out.println(currentNode.data + " "); + inorder(currentNode.rightChild); + } + } + //후위순회 + public void postorder(Node currentNode) { + if(currentNode != null) { + postorder(currentNode.leftChild); + postorder(currentNode.rightChild); + System.out.println(currentNode.data + " "); + } + } + +} diff --git a/CJW/LinkedList.py b/CJW/LinkedList.py new file mode 100644 index 0000000..97fa698 --- /dev/null +++ b/CJW/LinkedList.py @@ -0,0 +1,64 @@ +class Node: + def __init__(self, data): + self.data = data + self.next = None + +class LinkedList: + head=Node(None) + + #헤더부터 탐색해 뒤에 새로운 노드 추가 + def append(self, data): + cur = self.head + + while cur.next is not None: + cur=cur.next + cur.next = Node(data) + + + #모든 노드 값 출력 + def print_all(self): + cur = self.head + while cur is not Node: + print(cur.data) + cur = cur.next + + #노드 인덱스 알아내기 + def get_node(self, index): + curNode = self.head + cnt=0 + while cnt