분류 전체보기
-
1/13기록 - 백준 2309Algorithm 2022. 1. 13. 10:52
오늘은 브론즈 2 티어 백준 2309번 문제 일곱 난쟁이 문제를 풀어보았다. 문제는 정말 간단하다. 그냥 일곱 난쟁이였는데, 쁘락치 2명이 들어왔으니 7명 난쟁이 키의 합이 100이라는 조건으로 쁘락치 2명을 찾아내면된다. 이렇게 단순한 문제인데 7중 for문을 쓰는 말도 안 되는 짓은 일단 아닌거 같아서 배제하고, 어제 풀었던 없는 수 찾기 문제의 방식이 떠올라 전체에서 빼는 여사건 방식을 생각해 보았다. 9-2 = 7이니 두명의 쁘락치를 찾아서 전체 합에서 빼주면 될 것 같다. 그럼 2중 for문으로 돌리면서 if문으로 조건을 걸어주면 된다. 알고리즘 생각 1. BufferedReader와 크기 9짜리 height 배열을 선언하고 for문을 통해 9명의 키를 입력 받는다. 2. for문 안에서 sum..
-
1/12기록 - 프로그래머스 문제풀이 #3Algorithm 2022. 1. 12. 11:24
앞에 level 1 두 문제가 생각보다 너무 쉬워서 공부가 안 된 것 같은 찝찝함이 있어서 그냥 아무거나 level 1으로 한 문제만 더 풀자 하면서 세 번째 문제에 도전해 보았다. K번째 수 문제, 문제 이해가 조금 빡셀 수 있는데 차근차근 읽어보면, commands 배열안에 있는 수를 가지고 array배열을 잘라서 새로운 배열을 만들어 return 하는 거였다. 알고리즘 생각 1. commands.length 만큼 새로운 배열 answer를 생성한다. 2. 이차원 배열인 commands 배열의 가로 인덱스로 array 배열을 자를 시작과 끝을 표시한다.(배열 인덱스 시작이 0이라는 점 주의!!) 3. ArrayList 배열을 선언하고, for문으로 array 배열의 해당 인덱스를 하나씩 차례대로 담아..
-
1/12기록 - 프로그래머스 문제풀이 #2Algorithm 2022. 1. 12. 10:26
생각보다 없는 숫자 더하기 문제가 너무 간단해서 한 문제를 더 풀어보았다. 내적 문제이다. 미분적분학과벡터해석을 공부했기 때문인지 내적은 너무 익숙해서 문제를 보고 바로 이해해 버렸다. a와 b 배열의 인덱스끼리 곱해주면 되니 for문을 써주면 될 것 같았다. 처음에는 이중 for문을 썼더니 답이 다르길래 응??? 했지만, 바로 왜 이중 for문을 쓰면 안되는지 깨달아버렸다. 이중 for문을 쓰게 되면 i가 0일때 0~b.length-1 까지의 인덱스를 다 조사하고, 또 i가 1일때 0~b.length-1 까지의 인덱스를 다 조사한다. 그래서 단순 for문 안에서 a,b 배열의 0인덱스끼리, 1인덱스끼리 이런식으로 곱해주면 되는 거였다. 가뿐하게 통과!!!!!!!!
-
1/12기록 - 프로그래머스 문제풀이 #1Algorithm 2022. 1. 12. 10:21
오늘은 프로그래머스에서 level1 문제를 풀어보았다. 가장 먼저 풀어본 것은 없는 숫자 더하기 문제 이 문제는 오름차순으로 생각을 하게 되면, 정말 복잡하다. 처음에 배열 안에서 0~9까지의 숫자 중 없는 수를 찾기 위해 if문을 쓰면서 난리를 치다가 문득 든 생각이 0~9를 더한 값에서 numbers 배열안에 든 값을 for문으로 조사해서 더한 값을 빼주면 되겠다는 생각이 들었다. 생각보다 너무 단순하게 풀어졌다.... 나 뭐한거지....???? 여튼 정답!!!!!!
-
1/11기록 - 백준 2846Algorithm 2022. 1. 11. 10:15
백신 부스터샷을 맞고 혹시나 아프면 안하려고 했지만, 뭔가 괜찮은 듯 하여 오늘은 브론즈 2티어의 백준 2846 오르막길 문제를 도전해 보았다. 입력 예제를 보고 문제에 예를 든 것을 보고 나서야 겨우 이해가 되었다. 문제가 희한한 건지 백신 때문에 머리가 안돌아가는 건지... 어쨌든 오늘의 문제를 살펴보면, 증가하는 부분 수열이 오르막길이 되고 그런 오른 막길 중 가장 큰 오르막길을 찾아 시작지점과 끝지점을 뺀 값을 찾아 내는 문제이다. 알고리즘 생각 1. N 숫자 입력 받기(BufferedReader, StringTokenizer 사용) 2. 크기 N의 배열 선언 3. N만큼 for문을 돌려서 숫자를 N개 입력 받아 배열에 넣어줌 4. N만큼 for문을 돌리고 만약, 오르막길이라면 뒤-앞을 해서 임시..
-
HashMap 예제 #2Algorithm/Hash 2022. 1. 10. 11:01
프로그래머스 해시 파트 level 2 첫 번째 문제에 이어 두 번째 문제 위장문제를 도전해 보았다. 문제는 이러하다. 뭔가 문제에서 부터 Map을 쓰면 편할 것 같은 느낌이 확 풍겨온다. 하지만 막상 문제를 읽으면 서로 다른 옷의 조합의 수를 return 하란다 ㅋㅋㅋ 여튼 그럼 그냥 종류를 key로, 개수를 value로 하면 대놓고 Map으로 풀 수 있을것 같다. 제한 사항들과 함께 알고리즘을 생각해 보자. 1. clothes 배열을 보면 의상의 종류가 인덱스 [1] 부터 나열되고 있으므로, clothes[i][1] 인덱스를 사용해서 풀 수 있을 것 같다. 2. 같은 이름의 의상이 존재하지 않으므로, set이나 Map을 쓰면 될 듯하다. 3. clothes 원소가 문자열이므로, 제네릭안에 key의 타입..
-
1/10기록 - 백준 1009Algorithm 2022. 1. 10. 10:23
주말을 잘 쉬다가 오늘도 알고리즘 문제를 하나 풀어보았다. 오늘은 백준 1009번 분산처리 문제이다. a^b개의 형태로 주어진다는 것을 못보고 한참 동안 예제 출력이 왜 저렇게 되는지 고민한 것 같다..... 문제 잘보자 좀..... 내가 생각한 알고리즘은 a^b에서 시작한다. 당연히 a와 b를 입력받는 부분까지는 for문과 BufferedReader, StringTokenizer를 사용해서 표현해 주면 될 것이고, a^b가 뜻하는 것을 예제 입력을 통해 알아보자. 1 6 케이스 : 1^6은 뭘 해도 그냥 1이다. -> 출력 1 3 7 케이스 : 일의 자리 숫자에 주목해 보면, 3*3*3*3*3*3*3 -> 9,7,1,3이 반복된다는 것을 알 수 있고, 그럼 출력은 7 6 2 케이스 : 6*6 -> 일의..
-
1/7 기록 - 백준 1712번Algorithm 2022. 1. 7. 09:35
어제에 이어 가벼운 알고리즘 문제풀이를 해 보기 위해 백준을 켰다. 낮은 단계부터 차근히 해보자는 마음이었기 때문에 오늘 한 번 더 브론즈4 티어로 가서 문제를 골라보았다. 생각보다 정답률이 낮은 문제가 있어서 괜찮겠다 싶어서 문제를 도전해 보았다. 백준 1712번 손익분기점 문제이다. 처음에 손익분기점에 대한 내용을 잘 모르니 문제를 읽으면서 최대한 이해를 해 보려 했다. 손익분기점은 총 수입이 총 비용보다 많아져 이익이 발생하는 지점을 말한다고 한다. 그래서 어쩌라는거지.... 생각보다 꽤 고민한것 같은데 예시1을 통해 적용해 보자. 예시1 고정 비용 : 1000 가변 비용 : 70 판매 비용 : 170 총 수입 > 총 비용이 되려면 1개 팔았을 때, 170 < 1000+70 2개 팔았을 때, 170..