From dc9d61732659ada8f945b9e0c130bc794fa417af Mon Sep 17 00:00:00 2001 From: rover0811 Date: Tue, 26 Jul 2022 10:58:34 +0900 Subject: [PATCH 1/2] [Add] Algo 6~14 --- KHS/1021.py | 10 ++++++++++ KHS/11651.py | 7 +++++++ KHS/13116.py | 34 ++++++++++++++++++++++++++++++++++ KHS/1920.py | 22 ++++++++++++++++++++++ KHS/2012.py | 14 ++++++++++++++ KHS/2346.PY | 20 ++++++++++++++++++++ KHS/2805.py | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 143 insertions(+) create mode 100644 KHS/1021.py create mode 100644 KHS/11651.py create mode 100644 KHS/13116.py create mode 100644 KHS/1920.py create mode 100644 KHS/2012.py create mode 100644 KHS/2346.PY create mode 100644 KHS/2805.py diff --git a/KHS/1021.py b/KHS/1021.py new file mode 100644 index 0000000..57311f8 --- /dev/null +++ b/KHS/1021.py @@ -0,0 +1,10 @@ +from collections import deque +a=deque() + +for i in range(1,11): + a.append(i) + +def Number3(): + a.appendleft(a.pop()) +Number3() +print(a) \ No newline at end of file diff --git a/KHS/11651.py b/KHS/11651.py new file mode 100644 index 0000000..d273deb --- /dev/null +++ b/KHS/11651.py @@ -0,0 +1,7 @@ +import sys +N=int(sys.stdin.readline()) +a=[] +for i in range(N): + a.append(tuple(map(int,sys.stdin.readline().split()))) +for k,p in sorted(a,key=lambda a:(a[1],a[0])): + print(k,p) \ No newline at end of file diff --git a/KHS/13116.py b/KHS/13116.py new file mode 100644 index 0000000..e8416c5 --- /dev/null +++ b/KHS/13116.py @@ -0,0 +1,34 @@ +import sys + +def binary(input): + if input==1: + return input + elif input%2==1: + return int((input-1)/2) + elif input%2==0: + return int(input/2) + +a=[list(map(int,sys.stdin.readline().split())) for i in range(int(input()))] +b=[] +c=[] +d=[] +for i,k in a: + b.append(i) + c.append(k) + while True : + if i==1 and k==1: + break + elif i==1: + k=binary(k) + c.append(k) + elif k==1: + i=binary(i) + b.append(i) + else: + k=binary(k) + c.append(k) + i=binary(i) + b.append(i) + print(10*max(set(b)& set(c))) + b.clear() + c.clear() \ No newline at end of file diff --git a/KHS/1920.py b/KHS/1920.py new file mode 100644 index 0000000..206d19c --- /dev/null +++ b/KHS/1920.py @@ -0,0 +1,22 @@ +import sys +N=int(input()) +beforelist = list(map(int, sys.stdin.readline().split())) +M=int(input()) +afterlist = list(map(int, sys.stdin.readline().split())) +beforelist.sort() + +def binarySearch(after,number): + first=0 + last=number-1 + while(first<=last): + mid=(first+last)//2 + if after==beforelist[mid]: + return 1 + elif after> beforelist[mid]: + first=mid+1 + elif after< beforelist[mid]: + last=mid-1 + return 0 + +for j in afterlist: + print(binarySearch(j,N)) \ No newline at end of file diff --git a/KHS/2012.py b/KHS/2012.py new file mode 100644 index 0000000..7e341bd --- /dev/null +++ b/KHS/2012.py @@ -0,0 +1,14 @@ +import sys +N=int(sys.stdin.readline()) +a=[] + +for i in range(N): + a.append(int(sys.stdin.readline().rstrip())) + +checker=0 + +for k,v in enumerate(sorted(a)):# 앞이 인덱스 + if v!=k+1: + checker+=abs(v-k-1) + +print(checker) \ No newline at end of file diff --git a/KHS/2346.PY b/KHS/2346.PY new file mode 100644 index 0000000..bde2143 --- /dev/null +++ b/KHS/2346.PY @@ -0,0 +1,20 @@ +#풍선 터트리기 펑펑 +from collections import deque +import sys +N=int(input()) +a=deque(map(int,sys.stdin.readline().split())) + +# for i in range(5): +# a.append(int(input())) +# for i in a: +# print(i,end=" ") +indexcheck=0 +temp=0 +while a: + print(temp) + indexcheck+=a[temp] + a.remove(a[temp]) + if temp>len(a)-1: + temp-=len(a) + elif temp<-len(a): + temp+=len(a) diff --git a/KHS/2805.py b/KHS/2805.py new file mode 100644 index 0000000..ac23bb6 --- /dev/null +++ b/KHS/2805.py @@ -0,0 +1,36 @@ +import sys +input=sys.stdin.readline +N,M=map(int,input().split()) +a=list(map(int,input().split())) +sum=0 +min=1 +max=max(a) +mid=(min+max)//2 + +while min<=max: + sum=0 + for i in a: + if i-mid>=0: + sum+=i-mid + if sum==M: + break + elif sum>M: + min=mid+1 + elif sum beforelist[mid]: +# first=mid+1 +# elif after< beforelist[mid]: +# last=mid-1 +# return 0 \ No newline at end of file From e01dd012fe15b974c5c5e51c8399154679fd0c22 Mon Sep 17 00:00:00 2001 From: rover0811 Date: Tue, 26 Jul 2022 11:00:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Add]=20=EC=9D=B4=EC=A7=84=20=ED=8A=B8?= =?UTF-8?q?=EB=A6=AC=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KHS/main.cpp | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 KHS/main.cpp diff --git a/KHS/main.cpp b/KHS/main.cpp new file mode 100644 index 0000000..a7b02ab --- /dev/null +++ b/KHS/main.cpp @@ -0,0 +1,202 @@ + +#include +#include +#include + +class List; + +class pair; + +class Node; + + +class pair { +public: + pair(int classnum, int grade) { + this->classnum = classnum; + this->grade = grade; + } + + pair() {} + + int grade = 0; + int classnum = 0; +}; + +class Node { + friend List; + +private: + Node() {} +// ~Node(){delete this;}; + + Node(int classnum, int grade) { + data = pair(classnum, grade); + } + + pair data; + Node *leftlink = nullptr; + Node *rightlink = nullptr; +}; + +class List { +private: + Node *Head = nullptr;//루트 노드 아마 const여야하지 않을까 한번 루트는 영원한 루트 + Node *Temp = nullptr; +public: + List() { + } + + void insert(int a, int b) { + Node *temp = Head; + if (temp == nullptr) { + Head = new Node(a, b); + } else { + Temp = new Node(a, b); + while (1) { + if (Temp->data.classnum > temp->data.classnum) { + if (temp->rightlink == nullptr) { + temp->rightlink = Temp; + break; + } else { + temp = temp->rightlink; + } + } else if (Temp->data.classnum < temp->data.classnum) { + if (temp->leftlink == nullptr) { + temp->leftlink = Temp; + break; + } else { + temp = temp->leftlink; + } + } + } + } + } + + std::tuple Get(int key) { + Node *temp = Head; + Node *follower = Head; + while (1) { + if (temp == nullptr) { + std::cout << "탐색한 노드는 없습니다" << std::endl; + break; + } + if (temp->data.classnum > key) { + follower = temp; + temp = temp->leftlink; + } else if (temp->data.classnum < key) { + follower = temp; + temp = temp->rightlink; + } else { + std::cout << "탐색한 노드는 " << "(" << temp->data.classnum << "," << temp->data.grade << ")" << std::endl; + return std::tuple(temp, follower); + } + } + return std::tuple(nullptr, nullptr); + } + + + void Delete(int key) { + std::tuple(result) = Get(key);//temp, follower, Get 함수 접근 + Node *tempNode = std::get<0>(result); + Node *followingNode = std::get<1>(result); + Node *projectNode; + Node *parentprojectNode; + std::cout << "삭제를 목표하는 노드 " << "(" << tempNode->data.classnum << "," << tempNode->data.grade << ")" + << std::endl; + std::cout << "그 노드의 부모 노드" << "(" << followingNode->data.classnum << "," << followingNode->data.grade << ")" + << std::endl; + + if (tempNode->rightlink == nullptr && tempNode->leftlink == nullptr) {//자식이 없는 경우의 삭제 + if ((tempNode->data.classnum) > (followingNode->data.classnum)) { + followingNode->rightlink = nullptr; + delete tempNode; + } else { + followingNode->leftlink = nullptr; + } + } else if (tempNode->rightlink == nullptr && tempNode->leftlink != nullptr) {//삭제할 노드의 우는 비고, 좌는 안빔 + if (followingNode->data.classnum > tempNode->rightlink->data.classnum) { + followingNode->leftlink = tempNode->rightlink; + } else { + followingNode->leftlink = tempNode->leftlink; + } + delete tempNode; + } else if (tempNode->rightlink != nullptr && tempNode->leftlink == nullptr) {//삭제할 노드의 우는 차고, 좌는 빔 + if (followingNode->data.classnum > tempNode->rightlink->data.classnum) { + followingNode->rightlink = tempNode->leftlink; + } else { + followingNode->rightlink = tempNode->rightlink; + } + delete tempNode; + } else {//삭제할 노드가 자식이 2명 + std::tuple(findresult) = findrightMin(tempNode); + projectNode = std::get<0>(findresult); + parentprojectNode = std::get<1>(findresult); + std::cout << "삭제 될 노드를 대체할 우측 트리에서의 가장 작은 노드는 " << "(" << projectNode->data.classnum << "," + << projectNode->data.grade << ")" << std::endl; + std::cout << "삭제 될 노드를 대체할 노드의 부모 노드 " << "(" << parentprojectNode->data.classnum << "," + << parentprojectNode->data.grade << ")" << std::endl; + tempNode->data.classnum = projectNode->data.classnum;//목표하는 노드 초기화 진행 + tempNode->data.grade = projectNode->data.grade; + if (parentprojectNode->leftlink == projectNode) { + parentprojectNode->leftlink = nullptr; + delete projectNode; + } + else { + parentprojectNode->rightlink = nullptr; + delete projectNode; + } + } + } + + std::tuple findrightMin(Node *currentNode) { + currentNode = currentNode->rightlink; + Node *followingNode = currentNode; + while (currentNode != nullptr) { + if (currentNode->leftlink != nullptr) { currentNode = currentNode->leftlink; } + if (currentNode->leftlink == nullptr)break; + followingNode = followingNode->leftlink; + } + return std::tuple(currentNode, followingNode);//currentNode 목표하는 노드, followingNode 목표하는 노드의 부모 + } + + + void inorder() { + inorder(Head); + } + + void inorder(Node *currentNode) { + if (currentNode) { + inorder(currentNode->leftlink); + std::cout << "(학번: " << currentNode->data.classnum << ", 점수: " + << currentNode->data.grade << ")" << std::endl; + inorder(currentNode->rightlink); + } + } +}; + +int main() { + List a;//1 + a.insert(20220033, 90); + a.insert(20220050, 73); + a.insert(20220043, 99); + a.insert(20220011, 82); + a.insert(20220024, 78); + a.insert(20220046, 96); + a.insert(20220001, 72); + a.insert(20220008, 88); + a.insert(20220036, 77); + a.insert(20220056, 93); + a.insert(20220053, 82); + a.insert(20220059, 100);//1번 + a.inorder(); //2번 + a.Delete(20220050); //3번 + a.inorder(); //4번 + a.Delete(20220008); //5번 + a.inorder(); //6번 + a.Delete(20220056); //7번 + a.inorder(); //8번 + a.Get(20220056); //9번 + a.Get(20220043); //10번 + return 0; +}