728x90
๋ฐ์ํ
- ์์ ์ C++๋ก ํ์๋๋ฐ, ์๊ฐ ์ด๊ณผ๊ฐ ๋ฌ์๋ค.
- ๋ค์๋ด๋ C++์ ์ด์ฐ... ์ด์ ๋ชป ์ฐ๊ฒ ๋ค.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
long long solution(int n, vector<int> times) {
long long answer = 0;
sort(times.begin(), times.end());
vector<int> officer = times;
int passed = 0;
int i = 0;
while(passed < n)
{
officer[i]--;
if(officer[i] <= 0){
passed++;
officer[i] = times[i];
}
i++;
if(i >= officer.size()){
answer++;
i = 0;
}
}
return answer+1;
}
- ์ผ๋จ ์ด๊ฑธ ํ์ด์ฌ์ผ๋ก ๋จผ์ ์ฎ๊ธด๋ค.
- ๋ฌผ๋ก ๊ฒฐ๊ณผ๋ ๋์ผ. ์๊ฐ์ด๊ณผ.
def solution(n, times):
answer = 0
times.sort()
officer = times.copy()
passed = 0
i = 0
while passed < n:
officer[i] -= 1
if officer[i] <= 0:
passed += 1
officer[i] = times[i]
i += 1
if i >= len(officer):
i = 0
answer += 1
return answer + 1
- ์ด๋ฐ ๋ฐฉ์์ผ๋ก๋ ์๋๋ ใ ใ
def solution(n, times):
answer = 0
times.sort()
officer = times.copy()
len_officer = len(officer)
passed = 0
while passed < n:
min_time = min(officer)
for i in range(len_officer):
officer[i] -= min_time
if officer[i] == 0:
passed += 1
officer[i] = times[i]
answer += min_time
return answer
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.04ms, 10.1MB)
ํ
์คํธ 2 ใ ํต๊ณผ (6.88ms, 10.3MB)
ํ
์คํธ 3 ใ ํต๊ณผ (1065.73ms, 10.3MB)
ํ
์คํธ 4 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 5 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 6 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 7 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 8 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 9 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
- ํ...
def solution(n, times):
answer = 0
times.sort() # ์ฒ๋ฆฌ ์๊ฐ
officers = [] # ์ฒ๋ฆฌํ ์ธ์ ์
officers.append(int(n/len(times)))
passed_time = times[0] * officers[0]
for i in range(1, len(times)):
officers.append(int(passed_time / times[i]))
for i in range(0, len(times)):
print("์๋:", times[i],"์ฒ๋ฆฌ ์ธ์:", officers[i],"์์ ์๊ฐ:", times[i] * officers[i])
print("๋จ์ ์ธ์:", n-sum(officers))
return answer
ํ
์คํธ 1
์
๋ ฅ๊ฐ ใ 6, [7, 10]
๊ธฐ๋๊ฐ ใ 28
์คํ ๊ฒฐ๊ณผ ใ ์คํํ ๊ฒฐ๊ด๊ฐ 0์ด ๊ธฐ๋๊ฐ 28๊ณผ ๋ค๋ฆ
๋๋ค.
์ถ๋ ฅ ใ
์๋: 7 ์ฒ๋ฆฌ ์ธ์: 3 ์์ ์๊ฐ: 21
์๋: 10 ์ฒ๋ฆฌ ์ธ์: 2 ์์ ์๊ฐ: 20
๋จ์ ์ธ์: 1
- ํ... ์ ์๋๋๊ฑฐ์ผ;
import numpy as np
def solution(n, times):
answer = 0
times.sort() # ์ฒ๋ฆฌ ์๊ฐ
officers = [] # ์ฒ๋ฆฌํ ์ธ์ ์
officers.append(int(n/len(times)))
officers_time = []
passed_time = times[0] * officers[0]
for i in range(1, len(times)):
officers.append(int(passed_time / times[i]))
fast_officer = min(officers)
for i in range(len(times)):
#print("์๋:", times[i],"์ฒ๋ฆฌ ์ธ์:", officers[i],"์์ ์๊ฐ:", times[i] * officers[i])
officers_time.append(times[i] * officers[i])
#print("๋จ์ ์ธ์:", n-sum(officers))
answer = min(officers_time)
#print(answer)
estimated_officers_time = officers_time.copy()
n = n - sum(officers)
for i in range(len(officers_time)):
estimated_officers_time[i] += times[i]
sorted_officers_time = np.sort(estimated_officers_time)
sorted_officers_index = np.argsort(estimated_officers_time)
for i in range(n):
#officers[sorted_officers_index[i]] += 1
officers_time[sorted_officers_index[i]] += times[sorted_officers_index[i]]
return max(officers_time)
ํ
์คํธ 1
์
๋ ฅ๊ฐ ใ 6, [7, 10]
๊ธฐ๋๊ฐ ใ 28
์คํ ๊ฒฐ๊ณผ ใ ํ
์คํธ๋ฅผ ํต๊ณผํ์์ต๋๋ค.
ํ
์คํธ 2
์
๋ ฅ๊ฐ ใ 7, [7, 10]
๊ธฐ๋๊ฐ ใ 30
์คํ ๊ฒฐ๊ณผ ใ ํ
์คํธ๋ฅผ ํต๊ณผํ์์ต๋๋ค.
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
ํ
์คํธ 2 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
ํ
์คํธ 3 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
ํ
์คํธ 4 ใ ์คํจ (172.63ms, 42.7MB)
ํ
์คํธ 5 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
ํ
์คํธ 6 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
ํ
์คํธ 7 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
ํ
์คํธ 8 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
ํ
์คํธ 9 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
- ๋ผ์ด๋ ๋ก๋น ๋ฐฉ์ ๊ฐ์๊ฑด ๊ทธ๋ฅ ์๋๋ค.
- ์๊ฐ ์ด๊ณผ...
import numpy as np
def solution(n, times):
num_people = len(times)
current_time = [0] * num_people
while n > 0:
for i in range(num_people):
if n <= 0:
break
current_time[i] += times[i]
n -= 1
return max(current_time)
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ์คํจ (0.01ms, 27.9MB)
ํ
์คํธ 2 ใ ์คํจ (0.13ms, 28.2MB)
ํ
์คํธ 3 ใ ์คํจ (0.80ms, 28.2MB)
ํ
์คํธ 4 ใ ์คํจ (15.61ms, 35.6MB)
ํ
์คํธ 5 ใ ์คํจ (54.60ms, 39.8MB)
ํ
์คํธ 6 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 7 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 8 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 9 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
- ํ ๋ฒ ๋ ํธ๋ผ์ด!
import numpy as np
def solution(n, times):
num_people = len(times)
average_time = 0
officers = [[0,0] for i in range(num_people)]
for i in range(num_people):
average_time += 1/times[i]
target = int(n / average_time + 0.9) + 1
for i in range(num_people):
officers[i][1] = target // times[i]
officers[i][0] = times[i] * (target // times[i])
n -= officers[i][1]
remind = [[0,0] for i in range(num_people)]
if n > 0:
for i in range(num_people):
next_time = officers[i][0] + times[i]
remind[i][0] = next_time
remind[i][1] = i #index
remind.sort()
if remind[n-1][0] != 0:
return remind[n-1][0]
else:
return max(officers[i][0] for i in range(num_people))
- ์ด๊ฒ ์๋๋ค?
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ์คํจ (0.02ms, 28.2MB)
ํ
์คํธ 2 ใ ์คํจ (0.24ms, 28.2MB)
ํ
์คํธ 3 ใ ํต๊ณผ (1.26ms, 28.5MB)
ํ
์คํธ 4 ใ ์คํจ (239.64ms, 55.6MB)
ํ
์คํธ 5 ใ ํต๊ณผ (217.75ms, 60.4MB)
ํ
์คํธ 6 ใ ํต๊ณผ (273.62ms, 61.8MB)
ํ
์คํธ 7 ใ ์คํจ (335.51ms, 63.5MB)
ํ
์คํธ 8 ใ ํต๊ณผ (270.54ms, 63.5MB)
ํ
์คํธ 9 ใ ์คํจ (๋ฐํ์ ์๋ฌ)
- ๊ฒฐ๊ตญ ์ํค๋ ๋๋ก ์ด๋ถํ์์ผ๋ก ใ
.ใ
- n๋ช ์ด ์ ๊ตญ์ฌ์ฌ๋ฅผ ๋ฐ๋ ์ต์ ์๊ฐ = ์ ์ผ ๋น ๋ฅธ ์ฌ์ฌ๋
- n๋ช ์ด ์ ๊ตญ์ฌ์ฌ๋ฅผ ๋ฐ๋ ์ต๋ ์๊ฐ = ์ ์ผ ๋๋ฆฐ ์ฌ์ฌ๋ * n๋ช
def solution(n, times):
times.sort()
min_time = times[0]
max_time = times[-1]* n
def binSearch(low, high):
mid = (high-low)//2
if mid == 0:
return high
mid += low
passed = 0
for t in times:
passed += mid // t
if passed >= n:
return binSearch(low, mid)
else:
return binSearch(mid, high)
return binSearch(min_time, max_time)
- ๊ดํ ๊ณ ์ง์ด์๋ค.
- ์ํค๋๋๋ก ํ๋๊ฒ ์ ์ผ ์ฝ๋ค.
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.10ms, 10.3MB)
ํ
์คํธ 3 ใ ํต๊ณผ (4.03ms, 10.1MB)
ํ
์คํธ 4 ใ ํต๊ณผ (381.12ms, 14MB)
ํ
์คํธ 5 ใ ํต๊ณผ (488.09ms, 14.2MB)
ํ
์คํธ 6 ใ ํต๊ณผ (338.49ms, 14.4MB)
ํ
์คํธ 7 ใ ํต๊ณผ (659.35ms, 14MB)
ํ
์คํธ 8 ใ ํต๊ณผ (652.15ms, 14MB)
ํ
์คํธ 9 ใ ํต๊ณผ (0.04ms, 10.2MB)
- ๊ณ ์์ ํ์ด
- ์ ๊ธฐํ ๋ฐฉ์...
def count(period, times):
cnt = 0
for time in times:
cnt += period // time
return cnt
def solution(n, times):
digit = 50
t = 0
for i in range(digit, -1, -1):
temp = t + 2**i
cnt = count(temp, times)
if cnt >= n:
if count(temp-1, times) < n:
return temp
else:
t = temp
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.19ms, 10.2MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.66ms, 10.2MB)
ํ
์คํธ 3 ใ ํต๊ณผ (7.16ms, 10.1MB)
ํ
์คํธ 4 ใ ํต๊ณผ (659.91ms, 14.2MB)
ํ
์คํธ 5 ใ ํต๊ณผ (853.45ms, 14.3MB)
ํ
์คํธ 6 ใ ํต๊ณผ (634.52ms, 14.2MB)
ํ
์คํธ 7 ใ ํต๊ณผ (1062.84ms, 14.2MB)
ํ
์คํธ 8 ใ ํต๊ณผ (995.41ms, 14.1MB)
ํ
์คํธ 9 ใ ํต๊ณผ (0.10ms, 10.2MB)
- ๋น์ท๋น์ทํ๋ค.
def solution(n, times):
answer = 0
begin = 0
end = 1 * 10 ** 18
times.sort()
while (begin <= end):
to_do_job = [n][0]
mid = (begin + end) // 2
for task_time in times:
to_do_job -= mid // task_time
if to_do_job <= 0:
end = mid -1
elif to_do_job > 0:
begin = mid +1
return begin
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.06ms, 10.3MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.46ms, 10.1MB)
ํ
์คํธ 3 ใ ํต๊ณผ (9.54ms, 9.99MB)
ํ
์คํธ 4 ใ ํต๊ณผ (992.07ms, 14.2MB)
ํ
์คํธ 5 ใ ํต๊ณผ (764.32ms, 14.3MB)
ํ
์คํธ 6 ใ ํต๊ณผ (1183.25ms, 14.5MB)
ํ
์คํธ 7 ใ ํต๊ณผ (1187.45ms, 14MB)
ํ
์คํธ 8 ใ ํต๊ณผ (624.74ms, 14.2MB)
ํ
์คํธ 9 ใ ํต๊ณผ (0.03ms, 10.3MB)
- ๋์ค์ ์๊ฐ ๋๋ฉด ํ๊ท ์๋๋ก ์ฐพ์๋ณด๋๊ฑฐ ๋ค์ ์ง๋ด์ผ์ง
728x90
๋ฐ์ํ