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
- 기계학습
- HTML
- SWEA
- 파이썬
- siss
- PHP 웹페이지 만들기
- CSS
- 풀이
- BOJ
- C언어
- XSS Game
- 숙명여자대학교 정보보안동아리
- hackctf
- 자료구조 복습
- Python
- WarGame
- 머신러닝
- 웹페이지 만들기
- hackerrank
- Sookmyung Information Security Study
- c++
- 숙명여자대학교 정보보안 동아리
- Javascript
- 드림핵
- c
- 생활코딩
- 백준
- lob
- BOJ Python
- The Loard of BOF
Archives
- Today
- Total
혜랑's STORY
[HackerRank] Jim and the Orders 본문
2주차 자유 문제
Practice > Algorithms > Greedy
풀이
Serve time이 적은 고객부터 출력하는 문제이다. (Serve time은 Order + Prep time이다.) pair로 Serve time과 고객의 번호를 기억한 뒤, Serve time이 작은 사람을 기준으로 내림차순으로 정렬하였다. 그 뒤, p[i].secone(고객의 번호)를 차례로 result 배열에 넣게 되면 Serve time이 적은 고객의 번호가 순서대로 저장되게 된다.
전체 코드는 다음과 같다.
vector<int> jimOrders(vector<vector<int>> orders) {
vector<pair<int, int>> p;
vector<int> result;
for(int i=0; i < orders.size(); i++){
p.push_back({(orders[i][0] + orders[i][1]), i+1});
}
sort(p.begin(), p.end());
for(int i=0; i<p.size(); i++){
result.push_back(p[i].second);
}
return result;
}
모든 테스트케이스를 통과한 것을 볼 수 있다.
'2021 SISS 21기 활동 > 2학기 C' 카테고리의 다른 글
[HackerRank] Closet Numbers (0) | 2021.09.24 |
---|---|
[HackerRank] Equal Stacks (0) | 2021.09.24 |
[HackerRank] Permuting Two Arrays (0) | 2021.09.17 |
[HackerRank] Mark and Toys (0) | 2021.09.12 |
[HackerRank] Jesse and Cookies (0) | 2021.09.12 |