diff --git a/BOJ_10815 b/BOJ_10815 new file mode 100644 index 0000000..7425884 --- /dev/null +++ b/BOJ_10815 @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; + +int main() { + int n, m; + cin >> n; + vector cards(n); + + for (int i = 0; i < n; i++) { + cin >> cards[i]; + } + + // 숫자 카드 배열 정렬 + sort(cards.begin(), cards.end()); + + cin >> m; + vector query(m); + for (int i = 0; i < m; i++) { + cin >> query[i]; + } + + for (int i = 0; i < m; i++) { + // 이분 탐색을 통해 query[i]가 cards에 있는지 확인 + if (binary_search(cards.begin(), cards.end(), query[i])) { + cout << "1 "; + } else { + cout << "0 "; + } + } + + cout << endl; + return 0; +} diff --git a/BOJ_16401 b/BOJ_16401 new file mode 100644 index 0000000..bbfaddf --- /dev/null +++ b/BOJ_16401 @@ -0,0 +1,40 @@ +#include +#include +#include +using namespace std; + +bool canDivideSnacks(const vector& snacks, int numChildren, int length) { + int count = 0; + for (int snack : snacks) { + count += snack / length; + if (count >= numChildren) return true; // 필요한 아이 수만큼 나눠줄 수 있으면 true + } + return count >= numChildren; +} + +int main() { + int numChildren, numSnacks; + cin >> numChildren >> numSnacks; + + vector snacks(numSnacks); + for (int i = 0; i < numSnacks; i++) { + cin >> snacks[i]; + } + + // 과자의 길이를 내림차순으로 정렬하여 큰 길이부터 탐색하도록 합니다. + sort(snacks.begin(), snacks.end(), greater()); + + int left = 1, right = snacks[0], answer = 0; + while (left <= right) { + int mid = (left + right) / 2; + if (canDivideSnacks(snacks, numChildren, mid)) { + answer = mid; // 가능한 길이이므로 저장 + left = mid + 1; // 더 큰 길이를 탐색 + } else { + right = mid - 1; // 길이가 부족하면 더 작은 길이를 탐색 + } + } + + cout << answer << endl; + return 0; +} diff --git a/BOJ_17266 b/BOJ_17266 new file mode 100644 index 0000000..13cb413 --- /dev/null +++ b/BOJ_17266 @@ -0,0 +1,39 @@ +#include +#include +#include +using namespace std; + +bool canLightUpTunnel(int height, const vector& positions, int tunnelLength) { + int currentCoverage = 0; + for (int pos : positions) { + if (currentCoverage < pos - height) { + return false; + } + currentCoverage = pos + height; + } + return currentCoverage >= tunnelLength; +} + +int main() { + int tunnelLength, numLights; + cin >> tunnelLength >> numLights; + + vector positions(numLights); + for (int i = 0; i < numLights; i++) { + cin >> positions[i]; + } + + int left = 1, right = tunnelLength, answer = tunnelLength; + while (left <= right) { + int mid = (left + right) / 2; + if (canLightUpTunnel(mid, positions, tunnelLength)) { + answer = mid; + right = mid - 1; + } else { + left = mid + 1; + } + } + + cout << answer << endl; + return 0; +} diff --git a/BOJ_2343 b/BOJ_2343 new file mode 100644 index 0000000..e847220 --- /dev/null +++ b/BOJ_2343 @@ -0,0 +1,45 @@ +#include +#include +#include +using namespace std; + +bool canDivideLectures(const vector& lessons, int numBluRays, int maxSize) { + int count = 1, currentSum = 0; + for (int lesson : lessons) { + if (currentSum + lesson > maxSize) { + count++; // 새로운 블루레이에 녹화 + currentSum = lesson; + if (count > numBluRays) return false; + } else { + currentSum += lesson; + } + } + return true; +} + +int main() { + int numLessons, numBluRays; + cin >> numLessons >> numBluRays; + + vector lessons(numLessons); + int maxLesson = 0, totalSum = 0; + for (int i = 0; i < numLessons; i++) { + cin >> lessons[i]; + maxLesson = max(maxLesson, lessons[i]); + totalSum += lessons[i]; + } + + int left = maxLesson, right = totalSum, answer = totalSum; + while (left <= right) { + int mid = (left + right) / 2; + if (canDivideLectures(lessons, numBluRays, mid)) { + answer = mid; // 가능한 블루레이 크기이므로 저장 + right = mid - 1; // 더 작은 크기를 탐색 + } else { + left = mid + 1; // 더 큰 크기를 탐색 + } + } + + cout << answer << endl; + return 0; +} diff --git a/BOJ_3079 b/BOJ_3079 new file mode 100644 index 0000000..9299f50 --- /dev/null +++ b/BOJ_3079 @@ -0,0 +1,42 @@ +#include +#include +#include +using namespace std; + +bool canProcessAll(int64_t time, const vector& times, int64_t numPeople) { + int64_t totalProcessed = 0; + for (int t : times) { + totalProcessed += time / t; // 각 심사대에서 주어진 시간 내에 처리할 수 있는 사람 수 + if (totalProcessed >= numPeople) return true; // 필요한 사람 수를 모두 처리할 수 있으면 true + } + return totalProcessed >= numPeople; +} + +int main() { + int numStations; + int64_t numPeople; + cin >> numStations >> numPeople; + + vector times(numStations); + int maxTime = 0; + for (int i = 0; i < numStations; i++) { + cin >> times[i]; + maxTime = max(maxTime, times[i]); + } + + int64_t left = 1, right = static_cast(maxTime) * numPeople; + int64_t answer = right; + + while (left <= right) { + int64_t mid = (left + right) / 2; + if (canProcessAll(mid, times, numPeople)) { + answer = mid; // 가능한 시간이면 저장 + right = mid - 1; // 더 작은 시간으로 탐색 + } else { + left = mid + 1; // 더 큰 시간으로 탐색 + } + } + + cout << answer << endl; + return 0; +}