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
- cpp
- horner algorithm
- 통계
- 이분탐색
- 백준
- 너비우선탐색
- 확률
- 알고리즘
- C#
- 9095 C++
- 문자열
- 입출력
- 프로그래머스C#
- 프로그래머스 c#
- dp
- 스티커 C++
- 수치해석
- horner
- 백준 C#
- 파라메트릭 서치
- 철자검사
- C++
- 코딩테스트
- C
- 확률론
- BFS
- 백준 9465
- 선형대수학
- 프로그래머스
- 통계학
Archives
- Today
- Total
HOIT_B
[ 프로그래머스 C++ ] 구명보트 본문
728x90
문제
https://school.programmers.co.kr/learn/courses/30/lessons/42885
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
몸무게 적은 순으로 정렬
1번 하고 n번 더해서 limit 보다 작으면 answer 1회 추가
시작 인덱스++, 시작이랑 끝이랑 같으니까 end--
더 크면 최소랑 탔는데 초과라 그냥 anwer++ , end--
코드
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> people, int limit) {
int answer = 0;
int start = 0; // 시작 인덱스
int end = people.size() - 1; //끝 인덱스
sort(people.begin(), people.end());
while (start <= end) {
if (people[start] + people[end] <= limit)
{
start++;
}
end--;
answer++;
}
return answer;
}
728x90
'작고소중한 알고리즘 풀기' 카테고리의 다른 글
[ 백준 C++ ] 1654번 랜선 자르기 (파라메트릭 서치) (0) | 2023.11.25 |
---|---|
[ 프로그래머스 C++ ] 피로도 (DFS) (1) | 2023.11.21 |
[ 백준 C++ ] 9465번 스티커 (0) | 2023.11.15 |
[ 백준 C++ ] 2170번 선 긋기 (0) | 2023.11.15 |
[프로그래머스 C++] 아이템 줍기 ( BFS ) (0) | 2023.11.15 |
Comments