검색결과 리스트
분류 전체보기에 해당되는 글 46건
- 2013.09.23 보물
- 2013.09.23 다리 놓기
- 2013.09.23 8진수 2진수
- 2013.09.23 시작
- 2013.08.08 08/08 (경찰 & 전화 & 병원 시리즈 script)
- 2013.08.02 08/01 (가족 & 집 역할 연기 관련 script)
- 2013.07.19 7/18 (스포츠 콘서트 관련 Script)
- 2013.06.26 [8주차]분할정복
- 2013.04.10 [2 - 2 주차]트리, 힙 구현과 탐색
- 2013.04.10 [2 - 1 주차] 포인터를 이용한 리스트
글
문제
옛날 옛적에 수학이 항상 큰 골칫거리였던 나라가 있었다. 이 나라의 국왕 김지민은 다음과 같은 문제를 내고 큰 상금을 걸었다.
길이가 N인 정수 배열 A와 B가 있다. 다음과 같이 함수 S를 정의하자.
S = A[0]*B[0] + ... + A[N-1]*B[N-1]
S의 값을 가장 작게 만들기 위해 A의 수를 재배열하자. 단, B에 있는 수는 재배열하면 안된다.
S의 최솟값을 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 N이 주어진다. 둘째 줄에는 A에 있는 N개의 수가 순서대로 주어지고, 셋째 줄에는 B에 있는 수가 순서대로 주어진다. N은 50보다 작거나 같은 자연수이고, A와 B의 각 원소는 100보다 작거나 같은 음이 아닌 정수이다.
출력
첫째 줄에 S의 최솟값을 출력한다.
예제 입력
예제 출력
한 쪽 배열을 오름차순으로 정렬하고
다른 한 쪽 배열을 내림차순으로 정렬하여 해결한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <iostream> using namespace std; int main() { int A[50], B[50]; int N; cin >> N; for ( int i=0;i<N;i++) { cin >> A[i]; } for ( int i=0;i<N;i++) { cin >> B[i]; } for ( int i=0;i<N;i++) { for ( int j=i+1;j<N;j++) { if (A[i] > A[j]) { swap(A[i], A[j]); } } } for ( int i=0;i<N;i++) { for ( int j=i+1;j<N;j++) { if (B[i] < B[j]) { swap(B[i], B[j]); } } } int sum=0; for ( int i=0;i<N;i++) { sum+=A[i]*B[i]; } cout << sum; } |
'Tip & Tech > 실전알고리즘' 카테고리의 다른 글
다리 놓기 (0) | 2013.09.23 |
---|---|
8진수 2진수 (0) | 2013.09.23 |
시작 (0) | 2013.09.23 |
트랙백
댓글
글
문제
재원이는 한 도시의 시장이 되었다. 이 도시에는 도시를 동쪽과 서쪽으로 나누는 큰 강이 흐르고 있다. 하지만 재원이는 다리가 없어서 시민들이 강을 건너는데 큰 불편을 겪고 있음을 알고 다리를 짓기로 결심하였다. 강 주변에서 다리를 짓기에 적합한 곳을 사이트라고 한다. 재원이는 강 주변을 면밀히 조사해 본 결과 강의 서쪽에는 N개의 사이트가 있고 동쪽에는 M개의 사이트가 있다는 것을 알았다. (N ≤ M)
재원이는 서쪽의 사이트와 동쪽의 사이트를 다리로 연결하려고 한다. (이때 한 사이트에는 최대 한 개의 다리만 연결될 수 있다.) 재원이는 다리를 최대한 많이 지으려고 하기 때문에 서쪽의 사이트 개수만큼 (N개) 다리를 지으려고 한다. 다리끼리는 서로 겹쳐질 수 없다고 할 때 다리를 지을 수 있는 경우의 수를 구하는 프로그램을 작성하라.
입력
입력의 첫 줄에는 테스트 케이스의 개수 T가 주어진다. 그 다음 줄부터 각각의 테스트케이스에 대해 강의 서쪽과 동쪽에 있는 사이트의 개수 정수 N, M (0 < N ≤ M < 30)이 주어진다.
출력
각 테스트 케이스에 대해 주어진 조건하에 다리를 지을 수 있는 경우의 수를 출력한다.
예제 입력
예제 출력
조합(combination)을 구하는 문제로 해석할 수 있다.
보통 고등학교에서 배우는 방법대로 조합을 구하다 보면 integer overflow가 발생할 수 있고
반복된 연산으로 Time-Limit 될 수 있다.
그렇기 때문에 배열을 이용하여 조합을 나타내 보기로 했다. (Dynamic Programming)
아래는 nCr을 나타낸 표이다.
nCr |
r = 1 |
2 |
3 |
4 |
5 |
6 |
n = 1 |
1 |
|
|
|
|
|
2 |
2 |
1 |
|
|
|
|
3 |
3 |
3 |
1 |
|
|
|
4 |
4 |
6 |
4 |
1 |
|
|
5 |
5 |
10 |
10 |
5 |
1 |
|
6 |
6 |
15 |
20 |
15 |
6 |
1 |
이 표를 배열로 나타낸다고 했을 때
arr[i][j] = arr[i-1][j-1] + arr[i][i-1][j] 라는 규칙을 찾을 수 있다.
이 규칙을 이용하여 표를 모두 채우고 시작한다면 조합을 쉽게 찾을 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <iostream> using namespace std; int main() { int dp[30][30] = {0,}; for ( int i=0;i<30;i++) { dp[0][i] = i+1; } for ( int i=1;i<30;i++) { for ( int j=1;j<30;j++) { dp[i][j] = dp[i-1][j-1] + dp[i][j-1]; } } int T, N, M; cin >> T; while (T--) { cin >> N >> M; cout << dp[N-1][M-1] << endl; } } |
문제 출처 : http://www.acmicpc.net/
'Tip & Tech > 실전알고리즘' 카테고리의 다른 글
보물 (0) | 2013.09.23 |
---|---|
8진수 2진수 (0) | 2013.09.23 |
시작 (0) | 2013.09.23 |
트랙백
댓글
글
문제
수가 8진수로 주어지면, 이를 2진수로 변환하는 프로그램을 작성하시오.
입력
첫째 줄에 수가 8진수로 주어진다. 주어지는 수의 길이는 333,334를 넘지 않는다.
출력
첫째 줄에 주어진 수를 2진수로 변환하여 출력한다. 수가 0인 경우를 제외하고는 반드시 1로 시작해야 한다.
예제 입력
예제 출력
8진수를 2진수로 바꾸라는 문제다.
복잡하게 문제를 해결하던 중 직관적이고 간단한 해법이 생각났다.
8진수, 0부터 7까지의 모든 경우의 수를 배열에 저장해보았다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <iostream> #include <cstring> using namespace std; int main() { char str[333335]; cin >> str; char dic1[8][4] = { "000" , "001" , "010" , "011" , "100" , "101" , "110" , "111" }; char dic2[8][4] = { "" , "1" , "10" , "11" , "100" , "101" , "110" , "111" }; cout << dic2[str[0]- '0' ]; int len = strlen (str); for ( int i=1;i<len;i++) { cout << dic1[str[i]- '0' ]; } } |
문제 출처 : http://www.acmicpc.net/
'Tip & Tech > 실전알고리즘' 카테고리의 다른 글
보물 (0) | 2013.09.23 |
---|---|
다리 놓기 (0) | 2013.09.23 |
시작 (0) | 2013.09.23 |
트랙백
댓글
글
우리 실전알고리즘은
ACM-ICPC (대학생 프로그래밍 경시대회) 형식의 문제를 풀어보고자 그룹 스터디를 시작하게 되었습니다.
교재는 따로 없으며 http://www.acmicpc.net/ 의 문제를 풀어갈 계획입니다.
'Tip & Tech > 실전알고리즘' 카테고리의 다른 글
보물 (0) | 2013.09.23 |
---|---|
다리 놓기 (0) | 2013.09.23 |
8진수 2진수 (0) | 2013.09.23 |
트랙백
댓글
글
경찰 & 전화 & 병원 시리즈 script
Question]
You may chat on the phone. With whom do you usually talk and how often do you talk on the phone? And what topic do you talk about?
Answer]
Yes, I love chatting on the phone. I chat with my friends most of time. I talked to my college friend last night. We just talked about our situation .Both of us are unemployed at the moment and we are both hunting for a new job. She told me to come with her next week for a walk-in application in one company. We also talked in relation to the recent updates in our friend's and experiences. We always have a lot to talk about. different topics every night and we never run out of topics to discuss over the phone. It is good to keep in touch with my friends through the phone.
Question]
For how long do you talk over the phone? And tell me about the advantages of using a phone for chatting.
Answer]
When I am not working and i'm just at home, I chat over the phone for hours. I always call all my friends and sometimes do a call conference with them. it takes more than an hour when we have a call conference. I spend almost my entries day just chatting with my friends. I think chatting over the phone has plenty of advantages. you can send SMS and music through your mobile phone. You'll be able to see face to face with the person on the other line and you can do a conference all. It it fun to talk to many people at their same time. Phones also come in handy to use
Question]
When was the time when you had a long chat for a long time recently? Was it about a good thing or bad thing? Please tell me in as much detail as possible.
Answer]
I had a very long chat with my colleague from my previous company last night. it was a good thing at first because we got to talk about the past and our recent endeavors. She told me about her promotion at work. I got really envious of her and her higher position. I thought that I have always worked harder than her. But, actually, I'm not in a good state right now. I just thought that it was unfair. I asked her secret to her success and she gave me some tips, so maybe I can also be successful. I am still very upset for myself, yet it was good to hear her secret to success.
'OPIC' 카테고리의 다른 글
08/01 (가족 & 집 역할 연기 관련 script) (0) | 2013.08.02 |
---|---|
7/18 (스포츠 콘서트 관련 Script) (0) | 2013.07.19 |
04/04 (외국어 공부 script) (0) | 2013.04.04 |
03/28 (음악 감상관련 Script) (0) | 2013.04.01 |
03/24 (인터넷 서핑관련) (0) | 2013.03.24 |
트랙백
댓글
글
가족 & 집 역할 연기 관련 script
Question]
I am going to give you a situation for you to act out. Let's assume that you need new furniture at home but your parent don't want to have it. Explain why you need new furniture and convince them to get it by giving two alternatives.
Answer]
I really think we should buy new furniture for our house. We have to purchase a new kitchen cabinet and a study table. It is for our own benefit and we could use them for a long time. Our study table is too small for our documents and books now. So we must buy a bigger one to accommodate them. Our kitchen is also out of storage that's why I suggest that we purchase new storage furniture, where we could store the dry goods we have in the kitchen. I think it'll give more space to organize the house. if you don't want to buy furniture, we can pay for a laborer or a carpenter to make a storage cabinet and a study table for us. Which do you prefer?
Question]
I live in an apartment/house, too. Please ask me three or four questions that you wish to know about the place where I now live in.
Answer]
- Do you have a 24 hour transportation available in your neighborhood?
- Do you have 24 hours security in you vicinity?
- Can you tell me the design of your apartment? Is it more of an elegant apartment or just a typical apartment?
- Is your place accessible to markets, schools, and churches?
Question]
I am going to give you a situation for you to act out. One of your relatives wants you to take care of the house while he/she is on vacation. Ask three or four questions that you wish to know about ti.
Answer]
- When are you coming back from your trip?
- Where are you planning to travel?
- Can I invite my sister along to look after your house?
- Do you have any security systems to set up every night?
Question]
Unfortunately, you have a problem to solve. When you arrived at his/her house, the door was wide open and you are sure that someone broke in. First, look arount the house. Then, call the police to report burglary. explain the situation and offer them the right reason to come as soon as possible.
Answer]
Hello, police station? This is an emergency call. I am here at No.276 New Street, at my aunt's house. I think a burglar broke into the house. I don't know what to do. Will you come immediately? My Aunt and cousins went off for a trip early this morning so it is impossible for them to come back. The lights inside are off for a trip early this morning so it is impossible for them to come back. The lights inside are off and I can't hear anything. The door at the back of the house is wide open. Can you come as soon as possible? What can you suggest me to do while waiting for you? I really am in a panic here. There is a motorcycle parked beside the sidewalk and I think it is the burglar's. Please take action on this matter right away. The burglar might seize all our valuables.
'OPIC' 카테고리의 다른 글
08/08 (경찰 & 전화 & 병원 시리즈 script) (0) | 2013.08.08 |
---|---|
7/18 (스포츠 콘서트 관련 Script) (0) | 2013.07.19 |
04/04 (외국어 공부 script) (0) | 2013.04.04 |
03/28 (음악 감상관련 Script) (0) | 2013.04.01 |
03/24 (인터넷 서핑관련) (0) | 2013.03.24 |
트랙백
댓글
글
스포츠 콘서트 관련 Script
Question]
You replied in ther Background Survey that you watch sports games. What kind of sports games do you like to watch? Tell me about the reason you watch them in detail.
Answer]
I am not really a sporty person, yet I love watching ball games on TV. My most favorite game would be soccer. I think soccer player are very strong and well disciplined. The action in their court is really exiting and the fans are very supportive to their favorite player or team. I also think that soccer is a physical game but it has good rules and regulation for the benefit of the players. Most of soccer player are friendly to their fans. I say the because I usually see them waving or shaking hands with their fans after every games
Question]
You have answered that you go to concerts. How frequently and with whom do you go there?
Answer]
I go to concerts maybe thrice a year of more if there are really good artist that i'd like to see perform. But mostly it's three times a year. I commonly go with friends and family. I once went to Rain's Concert in seoul with my foreign friend who just visited Korea. I think that was two years ago. The concert made me become a huge fan of Crayon-Pop. Everybody enjoyed the concert and Crayon-Pop left us wanting more. I think the artist is very sociable. They are so entertaining and they has greate moves. Though their voice is not amazingly beautiful, I can say the they are talented and ther are a good entertainer.
Question]
I'd like to know about your activities at the concert hall. Can you tell me about all of your activities before the concert starts and after it ends?
Answer]
I went to Crayon-Pop's Concert in Seoul with my foregin friend last month. The things I do at concert are pretty much similar with other people. Before the concert starts, I ask my friend to go and buy something to eat, because I want to be ready for the concert. We usually buy a can of soda and cheese burger from a stall. After having a snack, I am ready to enjoy the night. After the concert, I take some pictures inside the hall. I also go to the autograph signing in front of the stage, but sadly I haven't got any autographs from any singers yet because there are always too many people waiting in line. So I normally just go to the souvenir shop and buy some merchandise ther I set off back home.
'OPIC' 카테고리의 다른 글
08/08 (경찰 & 전화 & 병원 시리즈 script) (0) | 2013.08.08 |
---|---|
08/01 (가족 & 집 역할 연기 관련 script) (0) | 2013.08.02 |
04/04 (외국어 공부 script) (0) | 2013.04.04 |
03/28 (음악 감상관련 Script) (0) | 2013.04.01 |
03/24 (인터넷 서핑관련) (0) | 2013.03.24 |
트랙백
댓글
글
'Tip & Tech > Power 알고리즘' 카테고리의 다른 글
[2주차] Tree복습, 정렬 알고리즘 (0) | 2013.04.02 |
---|---|
[1주차] Tree 기본개념 (0) | 2013.03.27 |
트랙백
댓글
글
struct linkedlist{ int data; struct linkedlist *next; struct linkedlist *prev; }; typedef struct linkedlist LINKEDLIST; typedef LINKEDLIST *LINK; void heapTree( LINK *node, int data ){ if( *node == NULL ){ *node = newList(data); }else{ if( (*node)->data > data ){ heapTree( &(*node)->prev , data ); }else{ heapTree( &(*node)->next , data ); } } } void preorder( LINK node ){ if(node->data != NULL) printf("%d",node->data); if(node->prev != NULL) preorder(node->prev); if(node->next != NULL) preorder(node->next); } void postorder( LINK node ){ if(node->prev != NULL) preorder(node->prev); if(node->next != NULL) preorder(node->next); if(node->data != NULL) printf("%d",node->data); } void inorder( LINK node ){ if(node->prev != NULL) preorder(node->prev); if(node->data != NULL) printf("%d",node->data); if(node->next != NULL) preorder(node->next); } void main(void){ LINK root = NULL;//= (LINK)malloc(sizeof(LINKEDLIST)); heapTree(&root,11); heapTree(&root,10); heapTree(&root,12); printf(" PREORDER : "); preorder(root); printf(" POSTORDER : "); postorder(root); printf(" INORDER : "); inorder(root); }
'Tip & Tech > 적절한관계' 카테고리의 다른 글
[2 - 1 주차] 포인터를 이용한 리스트 (0) | 2013.04.10 |
---|---|
[1주차] c언어 기본 (0) | 2013.04.10 |
트랙백
댓글
글
1 - 1 싱글 링크드 리스트
struct linkedlist{ int data; struct linkedlist *next; }; typedef struct linkedlist LINKEDLIST; typedef LINKEDLIST *LINK; LINK newList( int data ){ LINK list; list = (LINK)malloc(sizeof(LINKEDLIST)); list->data = data; list->next = NULL; return list; } void appendList( LINK list, LINK argu ){ list->next = argu; } LINK findList( LINK head, int value ){ LINK list = head; while(list->data != value){ list = list->next; if(list->next == NULL){ break; } } return list; } void deleteList( LINK head, LINK find ){ find->prev->next = find->next; free(find); } void printList( LINK head ){ LINK print = head->next; while(print != NULL){ printf("%d\n",print->data); print = print->next; } } void main(void){ head = newList(-1); appendList( head, newList(4) ); appendList( head, newList(3) ); appendList( head, newList(2) ); appendList( head, newList(1) ); deleteList( head, findList( head, 1 ) ); deleteList( head, findList( head, 3 ) ); printList(head); }
2 - 1 더블 링크드 리스트
struct linkedlist{ int data; struct linkedlist *next; struct linkedlist *prev; }; typedef struct linkedlist LINKEDLIST; typedef LINKEDLIST *LINK; LINK newList( int data ){ LINK list; list = (LINK)malloc(sizeof(LINKEDLIST)); list->data = data; list->next = NULL; list->prev = NULL; return list; } void appendList( LINK list, LINK argu ){ list->next->prev = argu; argu->next = list->next; list->next = argu; argu->prev = list; } LINK findList( LINK head, int value ){ LINK list = head; while(list->data != value){ list = list->next; if(list->next == NULL){ break; } } return list; } void deleteList( LINK head, LINK find ){ find->next->prev = find->prev; find->prev->next = find->next; free(find); } void printList( LINK head ,LINK tail){ LINK print = head->next; while(print != tail){ printf("%d\n",print->data); print = print->next; } } void init( LINK head, LINK tail ){ head->next = tail; tail->prev = head; } void main(void){ head = newList(-1); tail = newList(-1); init( head, tail ); appendList( head, newList(4) ); appendList( head, newList(3) ); appendList( head, newList(2) ); appendList( head, newList(1) ); deleteList( head, findList( head, 1 ) ); deleteList( head, findList( head, 3 ) ); printList(head,tail); }
'Tip & Tech > 적절한관계' 카테고리의 다른 글
[2 - 2 주차]트리, 힙 구현과 탐색 (0) | 2013.04.10 |
---|---|
[1주차] c언어 기본 (0) | 2013.04.10 |
RECENT COMMENT