Algorithm
-
Review on PSAD 5.5카테고리 없음 2017. 6. 10. 18:08
While I was studying "Problem Solving with Algorithms and Data Structures using Python", I encountered two things that look very interesting. First of all, I became very interested in why Python allows a comma at the end of the list. I could find a interesting discussion on a stackoverflow page. To sum up, it is allowed to make it easier to edit multi-line lists.Second thing that I caught my att..
-
Review on PSAD 3.5카테고리 없음 2017. 5. 5. 12:19
While I was studying Problem Solving Algorithms and Data Structures using Python, I found that some of you might need more explanation on how to run the code in listings. How to use pythonds? pythonds is a package that has the basic data structures written in Python. You can down load it where the book is pointing: http://www.pythonworks.org/pythonds After downloading it, you need to install it ..
-
Review on PSAD 2.4카테고리 없음 2017. 5. 4. 17:23
While I was studying Problem Solving with Algorithms and Data Structure using Python, I have found some interesting features on Python. 1. Python has a ord() It is very interesting that there's a function returning a integer representing the Unicode code point of the character. Please have a look at this page for buit-in functions: https://docs.python.org/2/library/functions.html 2. Declaring an..
-
PSAD review on 1.13카테고리 없음 2017. 5. 2. 13:01
While I was studying PSAD, I found some interesting python features and would like to give some feedback. 1. Python has //, even tough it doesn't have ++ Interestingly, Python has '//' operator. What it does is returning the division value flooring the fraction. Please check http://stackoverflow.com/questions/183853/in-python-2-what-is-the-difference-between-and-when-used-for-division On the oth..
-
Interesting Python features (?)카테고리 없음 2017. 5. 2. 11:26
While I was studying "Problem Solving with Algorithms and Data Structures using Python", I found some interesting features (or syntax) while studying chapter 1. 1. It has "elif" You might have found you want several "else if" statements. Python helps you by shortening it to "elif". Please check https://docs.python.org/3/tutorial/controlflow.html 2. Your fraction may be different from other Pytho..
-
[문제해결을 위한 창의적 알고리즘] 전깃줄 (고급, p249)알고리즘 2017. 4. 15. 21:06
이 문제도 풀이가 바로 떠오르지 않을 것 같은 문제이다. 문제에서는 교차하는 전깃줄을 없애는 방법으로 A(왼쪽) 전봇대 위치를 정렬하고난 후, B(오른쪽) 전봇대 위치의 숫자로 만들 수 있는 오름차순 순열의 최대 길이를 구하는 문제로 일단 변경시켰다. 그 다음 IDT (인덱스 트리)를 이용하여, B 전봇대의 값을 차례로 읽으면서 나보다 작은 값들이 몇개 있나를 업데이트 해 나간다. 모든 값을 읽은 다음 제일 윗 칸 즉, IDT 행렬의 첫번째 값이 오름 차순 순열을 만들 수 있는 최대 길이 값이 되고, 전체 입력 개수에서 최대 길이 값 만큼을 뺀 숫자가 결국 없애야 하는 전깃줄의 숫자가 된다는 풀이 내용이다. 풀이에서는 sort (정렬)을 위해 라이브러리를 사용하고 있으나, 여기서는 알고리즘을 배우는 사람..
-
[문제해결을 위한 창의적 알고리즘] 경비행기 (고급, p232)알고리즘 2017. 4. 1. 23:06
이 문제도 이분 탐색에 의한 결정 문제이다. 처음 문제를 보면서 해결 방법을 찾기란 쉽지 않을 수도 있지만, 이분 탐색 결정으로 푸는 해결 방법을 어느정도 머리속에 넣어 놓고 있으면, 풀만한 문제인 것 같다. 여기서는 자바로 구현하면서 스퀘어 루트 함수를 사용하지 않고 또한 큐도 사용하지 않고 구현해 보았다. import java.util.Scanner; public class LightFlightSol236 {static class P{public int x;public int y;} public static int N;public static int K;public static int T;// 시작점과 도착점을 제외하고 경유할 수 있는 비행장이 최대 1000개이므로, 1002개로 선언public st..
-
[문제해결을 위한 창의적 알고리즘] 암벽등반 (고급, p225)알고리즘 2017. 3. 11. 23:34
이 문제 역시 이분 탐색을 이용한 결정 문제이다. 문제에서 3/4이상을 지나다녀야 한다는 제약 조건이 있는데, 이를 위해 모든 지점에서 모두 출발해 보며 확인할 것이 아니라, 1/4을 초과한 지점만 확인해 보면 된다는 아이디어가 더해져 더 빠르게 수행할 수 있도록 푸는 방법을 적용해 보았다. import java.util.Scanner; public class ClimbingSol231 { public static int N; // N이 500까지 이므로 500으로 선언 public static int[][] M = new int[500][500]; public static boolean[][] chk= new boolean[500][500]; // 상,하,좌,우 탐색 방향 설정 public static..