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
- 수학
- 그리디 알고리즘
- 스택
- 투 포인터
- 자료구조
- 백트래킹
- 유니티
- ue5
- c++
- 유니온 파인드
- 누적 합
- 정렬
- 재귀
- Unreal Engine 5
- 다이나믹 프로그래밍
- VR
- Team Fortress 2
- 그래프
- 시뮬레이션
- 문자열
- 트리
- 알고리즘
- 다익스트라
- 구현
- BFS
- 우선순위 큐
- DFS
- 백준
- 브루트포스
- XR Interaction Toolkit
Archives
- Today
- Total
1일1알
백준 5545번 최고의 피자 C++ 본문
https://www.acmicpc.net/problem/5545
5545번: 최고의 피자
상근이는 근처 피자 가게에서 매일 저녁으로 피자를 배달해 먹는다. 주머니 사정이 얇아진 상근이는 이번 달부터는 "최고의 피자"를 구매하려고 한다. 최고의 피자란, 피자 가게에서 주문할 수
www.acmicpc.net
토핑의 열량들을 내림차순으로 정렬하고 큰거부터 하나씩 적용해보면서 1원당 열량이 줄어들기 전까지만 토핑을 추가한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int calory = 0;
int price = 0;
vector<int> calories;
int n;
cin >> n;
int a, b;
cin >> a >> b;
price += a;
int c;
cin >> c;
calory += c;
for (int i = 0; i < n; i++) {
int d;
cin >> d;
calories.push_back(d);
}
sort(calories.begin(), calories.end(), greater<>());
for (int i = 0; i < n; i++) {
int nextPrice = price + b;
int nextCalory = calory + calories[i];
if (calory / price > nextCalory / nextPrice) break;
price = nextPrice;
calory = nextCalory;
}
cout << calory / price;
}
'알고리즘' 카테고리의 다른 글
백준 17086번 아기 상어 2 C++ (0) | 2022.12.15 |
---|---|
백준 12789번 도키도키 간식드리미 C++ (0) | 2022.12.14 |
백준 1485번 정사각형 C++ (0) | 2022.12.12 |
백준 13904번 과제 C++ (0) | 2022.12.11 |
백준 1774번 우주신과의 교감 C++ (0) | 2022.12.10 |