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 |
Tags
- 원판 돌리기
- 조세퍼스 순열
- qorwns
- C/C++ 구현
- 구현
- dfs
- 백준
- 자료구조
- ㅣ풀이
- 백준 1158
- 해시구현
- 스택의 특징
- 백준 17779
- 시간 복잡도
- 백준 2447
- 게리멘더링2
- heap
- 백준 5397
- 버킷 정렬
- 백준 1406
- 해시 구현
- 백준 17822
- c#
- AVL 시간 복잡도
- 5397
- 백준 17471
- 별 찍기 10
- 풀이
- 1764
- Stack 이란
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 2343] 기타 레슨 본문
https://jaimemin.tistory.com/1130
위 링크를 참조하였다
분류 : 이분탐색
요구사항
레코드의 최소길이 구하기
풀이
원하는 길이를 찾아야 한다
길이를 정하고 지금 정한 길이가 조건에 부합하는지 확인한다
길이가 오름차순으로 안주어질수도 있어서 정렬하고나서 정답출력하니 틀렸다고 한다
왜그런지 알수가 없당
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string.h>
//#include <map>
#include <string>
using namespace std;
int n, m;
int map[100100];
int ssum = 0;
bool check(int now) {
int sum = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
sum += map[i];
if (sum > now) {
sum = map[i];
cnt++;
}
}
if (now*cnt >= ssum)
return true;
// cout << "cnt" << cnt << endl;
return false;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &map[i]); ssum += map[i];
}
sort(map, map + n);
//for (int i = 0; i < n; i++) printf("%d ", map[i]);
int low = 1;
int high = 100000;
int ans = 0;
while (low <= high) {
int mid = (low + high) / 2;
if (check(mid)) {
low = mid+1;
}
else {
ans = mid;
high = mid-1;
}
// cout << mid << endl;
}
cout <<ans << endl;
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 1699] 제곱수의 합 (0) | 2020.03.24 |
---|---|
[백준 1719] 택배 (0) | 2020.03.24 |
[백준 4386] 별자리 만들기 (0) | 2020.03.23 |
[백준 1647] 도시 분할 계획 (0) | 2020.03.23 |
[백준 6497] 전력난 (0) | 2020.03.23 |
Comments