This is my result of the individual project from Algorithm class CSCI 3101 Hawaii Pacific University.

알고리듬 수업에서 수행한 개인 프로젝트의 결과물입니다.


Freckles Skiena and Revilla Programming Challenges book.

알고리즘 트레이닝 북에 실린 주근깨 문제입니다.


I implemented Prim and Kruskal algorithms for this project with Python. See attached files on the bottom of this post if you need.

You are allowed to edit attached source codes, but please do not remove my name as an author on the top.

참고로, 한국에서 판매하는 책에 해답(C로 작성된 소스코드)이 실려있지만, 실제로 작성해서 컴파일/실행해본 결과 제대로 작동이 되질 않았습니다. 따라서, 이것을 필자가 파이썬으로 재작성했고, 프로젝트의 조건은 Prim과 Kruskal 두 개의 알고리즘으로 구현해야하는 것이었습니다. 소스코드는 첨부된 하단에 파일을 참고해주세요. 내용은 수정해도 되지만, 제 이름은 삭제하지 말아주세요.


The below is the problem from the book.

아래는 알고리즘 트레이닝 북에 실린 문제의 원문입니다.



In an episode of the Dick Van Dyke television show, Dick’s son Richie connects the freckles on his father’s back to form a picture of the Liberty Bell. Consider Dick's back to be a plane with freckles at various (x, y) locations. Your job is to connect the dots so as to minimize the amount of ink used. Richie connects the dots by drawing straight lines between pairs, possibly lifting the pen between lines. When Richie is done there must be a sequence of connected lines from any freckle to any other freckle.


Input

The input begins with a single positive integer on a line by itself indicating the number of test cases, followed by a blank line.

The first line of each test case contains 0 < n <= 100, giving the number of freckles on Dick's back. For each freckle, a line follows; each following line contains two real numbers indicating the (x, y) coordinates of the freckle.

Put a blank line between each two consecutive test cases.


Output

For each test case, your program must print a single real number to two decimal places: the minimum total length of ink lines that can connect all the freckles. The output of each two consecutive cases must be separated by a blank line.


Sample Input

1

3
1.0 1.0
2.0 2.0
2.0 4.0

Sample Output

3.41 


---------------------------------------------------------------------------------------------------------

My source codes


Prim:






Kruskal:






HowItWorks.pdf


SeowonJung_Kruskal_Comment.py


SeowonJung_Prim_Comment.py


블로그 이미지

jswlinux

Seowon Jung의 잡동사니 보관소

,

여기 있는 에세이들은 맨위 2개의 Research paper만 제외하고 모두 제가 유학와서 처음 학교에 입학했을 때 ESL class에서 썼던 글들입니다.

따라서 문법이나 단어선택 등이 매우 부적절하고 옳지않은 경우가 많으니까 행여나 그대로 베끼지 마세요 ㅎㅎ

글의 내용이나 주제에 대한 참고 정도만 하시면 될 것 같습니다.

 

All my essays except the research paper were written when I was an ESL student. So therefore, there may be awkward words and wrong grammars.

Thank you for your visiting.

블로그 이미지

jswlinux

Seowon Jung의 잡동사니 보관소

,

오늘 새로나온 아이패드3를 구입하고 오면서 집 근처 악기점에 들러 그동안 사려고 벼르고있던 일렉기타를 샀다. 멕시코산 펜더 스트라토캐스터.

악기점 점원이 내가 보여달라는 기타에 앰프를 꽂아서 튜닝을 하고 직접 연주를 하게 해줬는데, 베이스기타와 피아노 외에는 칠 줄 아는 악기가 없는 관계로 소리를 들어봐야 뭐가 좋은지는 잘 모르겠더라. 어차피 이 기타로 연습을 하고 나중에 더 좋은 것을 사고, 이건 와이프를 주기로 약속을 한 터라 나보다는 와이프의 의견이 중요했고, 와이프는 무엇보다도 생김새와 색깔이 가장 중요했다...

레드와인 컬러와 펄이 들어간 은색(아이보리)의 기타 중에서 고른 건 와이프의 가장 좋아하는 컬러인 은색이였는데, 기타만 달랑 사갖고 차 뒷좌석에 눕혀놓으니 좀 뭔가 허전하긴 하더라… 뭐 입문용이니 일단은 크게 의미를 두지말고 그냥 연습용으로 열심히 써야겠다.

 

IMG 0098

IMG 0099

블로그 이미지

jswlinux

Seowon Jung의 잡동사니 보관소

,