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 | 31 |
Tags
- redis
- 열혈 TCP/IP 소켓 프로그래밍
- 제프리리처
- 우아한 테크 세미나
- FIFO paging
- 스프링 입문
- Operating System
- 스프링 핵심 원리
- C#
- 에러핸들링
- TCP/IP
- HTTP
- 윤성우 저자
- Window-Via-c/c++
- Operating System.
- 김영한
- 2475번
- 열혈 tcp/ip 프로그래밍
- BOJ
- 이펙티브코틀린
- Spring
- Four Squares
- 운영체제
- inflearn
- C++
- n타일링2
- OS
- 토마토
- 10026번
- 우아한레디스
Archives
- Today
- Total
나의 브을로오그으
[c++] 1654번 : 랜선 자르기 본문
https://www.acmicpc.net/problem/1654
1654번: 랜선 자르기
첫째 줄에는 오영식이 이미 가지고 있는 랜선의 개수 K, 그리고 필요한 랜선의 개수 N이 입력된다. K는 1이상 10,000이하의 정수이고, N은 1이상 1,000,000이하의 정수이다. 그리고 항상 K ≦ N 이다. 그
www.acmicpc.net
#include <iostream>
#include <limits.h>
using namespace std;
int cutToLineCount(int* LANs, int line, int K)
{
int cnt = 0;
for (int i = 0; i < K; ++i)
{
cnt += LANs[i] / line;
}
return cnt;
}
int cutToLongestLine(int* LANs, int max, int K, int N)
{
if (cutToLineCount(LANs, max, K) >= N)
{
return max;
}
int begin = 1;
int end = max;
int line = 0;
while (begin < end)
{
line = begin + (end - begin) / 2;
if (cutToLineCount(LANs, line, K) < N)
{
end = line;
}
else
{
begin = line + 1;
}
}
return begin - 1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int K = 0;
int N = 0;
int max = -1;
int line = 0;
cin >> K >> N;
int* LANs = new int[K];
for (int i = 0; i < K; ++i)
{
cin >> LANs[i];
max = max > LANs[i] ? max : LANs[i];
}
line = cutToLongestLine(LANs, max, K, N);
cout << line << '\n';
delete[] LANs;
return 0;
}
'알고리즘 > BaekJoon' 카테고리의 다른 글
[c++] 1920번 : 수 찾기 (0) | 2022.03.25 |
---|---|
[c++] 1874번 : 스택 수열 (0) | 2022.03.25 |
[c++] 1436번 : 영화감독 숌 (0) | 2022.03.22 |
[c++] 1259번 : 팰린드롬 수 (0) | 2022.03.22 |
[c++] 1181번 : 단어 정렬 (0) | 2022.03.20 |