Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- NRVO
- Unreal Engine5
- 프로그래머스
- 2294
- 티스토리챌린지
- Programmers
- Frustum
- DirectX11
- GeeksForGeeks
- C++
- C
- UnrealEngine4
- directx
- 백준
- 팰린드롬 만들기
- winapi
- const
- UnrealEngine5
- RootMotion
- 줄 세우기
- RVO
- baekjoon
- 오블완
- 언리얼엔진5
- algorithm
- softeer
- IFileDialog
- UE5
- TObjectPtr
- 1563
Archives
- Today
- Total
Game Develop
[Algorithm]Baekjoon 3079번 :: 입국심사 본문
https://www.acmicpc.net/problem/3079
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_map>
#include <stack>
#include <numeric>
#include <climits>
#include <bitset>
#include <cmath>
#include <mutex>
using namespace std;
int n, m; // n 10만, m 10억
int processingTimes[100000] = { 0 };
bool check(unsigned long long time)
{
// time이내에 m명이 전부 통과할 수 있는지를 체크해야됨.
// m값 최대 10억
unsigned long long sum = 0;
for (int i = 0; i < n; ++i) // 심사대 시간들
{
sum += time / processingTimes[i];
if (sum >= m)
{
return true;
}
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i)
{
cin >> processingTimes[i];
}
sort(processingTimes, processingTimes + n);
unsigned long long left = 0;
unsigned long long right = pow(10, 18);
unsigned long long answer = 0;
while (left <= right)
{
unsigned long long mid = (left + right) / 2;
if (check(mid))
{
right = mid - 1;
answer = mid;
}
else
{
left = mid + 1;
}
}
cout << answer;
}
|
cs |
구해야하는 최소시간을 mid값을 두고 이분탐색하면 되는데, 이 때 정해진 시간을 두고 이 시간 내에 모든 인원이 통과할 수 있는지를 알아내는게 포인트다.
이 유형이 꽤 알고리즘문제에서 자주 나오는 유형인 것 같긴하다.
생각보다 쉬운데, 그냥 각 심사대시간으로 나눠준 몫을 합쳤을 때 인원수 이상이면 전부 통과할 수 있다고 판단한다.
전부 검사할 필욘 없으니, 처음에 심사대시간을 오름차순 정렬시켜주고 반복문 돌 때 인원수 넘기면 바로 true를 리턴하게 해주면 된다.
'Algorithm > Algorithm' 카테고리의 다른 글
[Algorithm]Baekjoon 17951번 :: 흩날리는 시험지 속에서 내 평점이 느껴진거야 (0) | 2025.09.18 |
---|---|
LCS (0) | 2023.11.06 |
MergeSort와 QuickSort (0) | 2022.12.27 |
음수사이클이 있는 그래프 (다익스트라, 벨만포드, 플로이드와샬) (1) | 2022.12.26 |
나머지연산 공식. (0) | 2022.12.04 |