개발/코딩29 백준 - 보물 - Swift 수학 그리디 알고리즘 정렬 import Foundation let N = Int(readLine()!)! let arrayA = readLine()!.split(separator: " ").map{Int(String($0))!} let arrayB = readLine()!.split(separator: " ").map{Int(String($0))!} let sortedA = arrayA.sorted(by: { $0 $1}) var sum = 0 for i in 0 ..< N { sum += sortedA[i] * sortedB[i] } print(sum) https://www.acmicpc.net/problem/1026 1.. 2022. 7. 10. 백준 - 회의실 배정 - Swift https://www.acmicpc.net/problem/1931 1931번: 회의실 배정 (1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다. www.acmicpc.net 그리디 알고리즘 정렬 import Foundation let N = Int(readLine()!)! var meetings:[[Int]] = [] for _ in 0 ..< N { var meeting:[Int] = [] meeting = readLine()!.split(separator: " ").map{Int(String($0))!} meetings.append([meeting[0],meeting[1]]) } let sorted = meetings.sorted(by: {( $0[1],$0[0]) < ($1[1.. 2022. 7. 10. 백준 - 동전 0 - Swift https://www.acmicpc.net/problem/11047 11047번: 동전 0 첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) 둘째 줄부터 N개의 줄에 동전의 가치 Ai가 오름차순으로 주어진다. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2인 경우에 Ai는 Ai-1의 배수) www.acmicpc.net 그리디 알고리즘 import Foundation let input1 = readLine()!.split(separator: " ").map{Int(String($0))!} let kindsOfCoin = input1[0] let valueOfCoin = input1[1] var coins:[Int] = [] for _ in 0 ..<.. 2022. 7. 10. 백준 - ATM - Swift https://www.acmicpc.net/problem/11399 11399번: ATM 첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000) www.acmicpc.net 그리디 알고리즘 정렬 import Foundation let N = Int(readLine()!)! var times = readLine()!.split(separator: " ").map{Int(String($0))!} var sorted = times.sorted(by: 2022. 7. 10. 백준 - 설탕 배달 - Swift https://www.acmicpc.net/problem/2839 수학 다이나믹 프로그래밍 그리디 알고리즘 import Foundation var kgSugar = Int(readLine()!)! var bags = 0 while kgSugar >= 0 { if kgSugar % 5 == 0 { bags += kgSugar / 5 print(bags) exit(0) } kgSugar -= 3 bags += 1 } print(-1) exit(0) 2022. 7. 10. 해커랭크(HackerRank) - Almost Sorted // C++ https://www.hackerrank.com/challenges/almost-sorted/problem Almost Sorted | HackerRank Sort an array by either swapping or reversing a segment www.hackerrank.com void segmentSort(vector* arr, int from, int to) { sort(arr->begin()+from, arr->begin()+to+1); } bool isASC(vector arr, int from, int to) { int prev = arr[from]; for(int i = from+1; i arr[i]) { return false; } prev = arr[i]; } return tru.. 2021. 5. 19. 해커랭크(HackerRank) - The Grid Search // C++ 해커랭크(HackerRank) - The Grid Search // C++ https://www.hackerrank.com/challenges/the-grid-search/problem string gridSearch(vector G, vector P) { int gridRow = G.size(); int gridCol = G[0].length(); int patternRow = P.size(); int patternCol = P[0].length(); for(int j = 0 ;j 2021. 5. 16. [hackerrank] Minimum Absolute Difference in an Array / C++ int minimumAbsoluteDifference(vector arr) { sort(arr.begin(),arr.end()); int diff = INT_MAX; for(int i = 0;i 2020. 12. 7. LeetCode - Two Sum / c++ https://leetcode.com/problems/two-sum Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com class Solution { public: vector twoSum(vector& nums, int target) { vector result; for(int i = 0 ;i 2020. 7. 24. 이전 1 2 3 4 다음