본문 바로가기

반응형

알고리즘 문제풀이

(66)
[Codeforces] Manthan, Codefest 18 (rated, Div. 1 + Div. 2) 6번째 코포 도전기, 풀이 시작합니다! A. Packetstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have nn coins, each of the same value of 11.Distribute them into packets such that any amount xx (1≤x≤n1≤x≤n) can be formed using some (possibly one or all) number of these packets.Each packet may only be used entirely or not used at all. No packet may be used ..
[프로그래머스] 2018 하반기 공채 대비 코딩테스트 실전 모의고사 1회 이번에 프로그래머스에서 공채 코댕 대비 코딩 테스트 실전 모의고사라는 느낌으로 문제를 출제했습니다!3 문제 이고, 2시간 반의 시험 시간을 가졌죠!생각보다 난이도가 쉬웠지만, 역시 생각보다 푸는 시간이 늦었네요 ㅋㅋㅋㅋ 그럼, 1번 부터 한 번 풀이를 시작하게씁니다! 참고로, 제가 푼 방법 말고도 공식적인 해설이 궁금하시다면, 여기를 가보세용! 1번 팰린드롬 문제 설명앞에서부터 읽을 때와 뒤에서부터 읽을 때 똑같은 단어를 팰린드롬(palindrome)이라고 합니다. 예를들어서 racecar, 10201은 팰린드롬 입니다.두 자연수 n, m이 매개변수로 주어질 때, n 이상 m 이하의 자연수 중 팰린드롬인 숫자의 개수를 return 하도록 solution 함수를 완성해 주세요.제한사항m은 500,000이하..
[BOJ] 1405. 미친로봇 미친 로봇 성공스페셜 저지클릭시 이동합니다.어떻게 풀까? 중요한 것은 이전에 왔던 경로에 도착하지 않는 경우의 확률만 구해야 한다는 것입니다.즉, DFS를 통해서, N번을 이동하면서, 자신의 위치를 visit처리 해준 다음에, visit처리 되지 않은 방향으로만 이동합니다!그리고, 각 방향으로의 확률이 있기 때문에, 자신이 현재 도착한 위치의 확률 * 다음으로 이동할 확률을 계속 곱해가면서, 자신의 현재 위치에 대한 확률을 계속 가지고 있습니다! 그리고, N번의 이동을 완료했으면, 결과 확률에 그 확률을 더해주고, 이전 상황으로 돌아가서, 다른 방향을 탐색합니다! 그림으로 예를 들어 드리겠습니다! 처음엔 이 장소에서 시작합니다! 오른쪽으로 이동할 수 있습니다!예제에서는 오른쪽 확률이 0.25이기 때문에,..
[BOJ] 2206. 벽 부수고 이동하기 벽 부수고 이동하기 성공클릭시 이동합니다. 어떻게 풀까? 최단 경로를 구하기위해 단순한 BFS로 풀려고하면 약간의 오류가 생깁니다!바로, 벽을 부술수 있는가? 의 유무 때문이죠! 따라서, 벽을 부술수 있는지의 여부를 따로 저장하기 위해 visit 배열을 2개 사용합시다!이렇게 관리하면, 평범하게 BFS를 돌려서 만약, (n,m)에 도착하면, 그 때의 이동 횟수를 출력하면 바로 그것이 최소 거리 입니다! 사실, 이 문제는 이전에 포스팅했던 미로탈출 과 아주 유사합니다!만약, 잘 이해가 안되시면 해당 포스팅을 확인해 주세용!! 코드 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354..
[Codeforces] AIM Tech Round 5 (rated, Div. 1 + Div. 2) 드디어 제가 풀었던 코포들 중에 마지막 코포 정리입니다!후후... 이 5번째 코포 풀이를 완성하면 왠지 떡상을 할 것 같은 좋은 느낌(?)이 듭니다. 후후후 A. Find Squaretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a table of size n×mn×m, initially fully white. Rows are numbered 11 through nn from top to bottom, columns 11 through mm from left to right. Some square inside the table with odd side le..
[Codeforces] Codeforces Round #506 (Div. 3) 드디어 지난번까지 풀었던 코드포스에 대한 풀이를 거의 다 올렸습니다. 조금만 더!!! A. Many Equal Substringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string tt consisting of nn lowercase Latin letters and an integer number kk.Let's define a substring of some string ss with indices from ll to rr as s[l…r]s[l…r].Your task is to construct such string ss of min..
[Codeforces] Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) 3번 째 코포 글입니다.으아... 이전에 풀었던거 복기하려고 하니 정말 미치겠네용기억이 잘 안나서 포스팅 하는데도 더 시간이 많이 걸리는 것 같아요. 어쩄든, 다시 시작합니다! 후욱.. 이거 말고도 2개 남았어요 흑흑... A. Doggo Recoloringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPanic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible co..
[Codeforces] Educational Codeforces Round 49 (Rated for Div. 2) 저의 2번째 코포입니다! 물론! 떡락했습니다 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ히잉... 떡상을 위해 다시 풀며 복습했던 내용을 블로그에 올리겠습니다!아자아자! A. Palindromic Twisttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string ss consisting of nn lowercase Latin letters. nn is even.For each position ii (1≤i≤n1≤i≤n) in string ss you are required to change the letter on this position eith..

반응형