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
- DFS
- 누적 합
- 백준
- 시뮬레이션
- ue5
- XR Interaction Toolkit
- 다이나믹 프로그래밍
- 다익스트라
- 우선순위 큐
- 유니온 파인드
- 브루트포스
- BFS
- 그래프
- 알고리즘
- 투 포인터
- 백트래킹
- c++
- 정렬
- 트리
- Unreal Engine 5
- 스택
- 재귀
- 유니티
- 자료구조
- Team Fortress 2
- 구현
- 문자열
- VR
- 수학
- 그리디 알고리즘
Archives
- Today
- Total
1일1알
백준 2594번 놀이공원 C++ 본문
https://www.acmicpc.net/problem/2594
2594번: 놀이공원
첫째 줄에 놀이기구의 개수 N이 주어진다. 이어 N줄에 걸쳐 각 놀이기구의 운행시작 시각과 종료 시각이 빈 칸을 사이에 두고 주어진다. 시각은 시간단위 두 자리, 분 단위 두 자리로 구성되며 오
www.acmicpc.net
앞시간-10, 뒷시간+10 를 pair로 저장해서 정렬하고 답을 구하면 되는데,
1100 1300, 1130 1230과 같이 늦게 시작하는 놀이기구가 먼저 시작하는 놀이기구보다 빨리 끝나는 경우를 조심해야한다.
#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 n;
vector<pair<int, int>> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<pair<int, int>>(n);
for (int i = 0; i < n; i++) {
string s, e;
cin >> s >> e;
int h_s = stoi(s.substr(0, 2));
int m_s = stoi(s.substr(2, 4));
int h_e = stoi(e.substr(0, 2));
int m_e = stoi(e.substr(2, 4));
v[i].first = h_s * 60 + m_s - 10;
v[i].second = h_e * 60 + m_e + 10;
}
v.push_back({ 0,600 });
v.push_back({ 1320,1320 });
sort(v.begin(), v.end());
int last = 600;
int ans = 0;
for (int i = 0; i < v.size() - 1; i++) {
int e = max(v[i].second, last);
int s = v[i + 1].first;
ans = max(ans, s - e);
last = max(last, e);
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 11265번 끝나지 않는 파티 C++ (0) | 2023.02.22 |
---|---|
백준 10166번 관중석 C++ (0) | 2023.02.21 |
백준 1464번 뒤집기 3 C++ (1) | 2023.02.19 |
백준 24230번 트리 색칠하기 C++ (0) | 2023.02.18 |
백준 1913번 달팽이 C++ (0) | 2023.02.17 |