그럴듯한 개발 블로그
반응형

https://www.acmicpc.net/problem/1931

 

1931번: 회의실 배정

(1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다.

www.acmicpc.net

예외처리를 생각 못하고 13퍼에서 터졌다. 기본 sort를 사용해서 회의 종료시간 기준이 아니라 시작 시간 기준으로 정렬되어 오류가 났다.. 사실상 코테 보러 가서 나온 문제면 fail이다.......... 백준 다시 좀 풀면서 예외처리를 신경써야겠다.

#include <string>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stack>
#include <unordered_set>
#include <utility>
using namespace std;
bool compare(std::pair<int, int> a, std::pair<int,int> b){
	if(a.second == b.second) // 끝나는 시간 즉 second를 기준으로 sort해야 함...
		return a.first < b.first;
	return a.second < b.second;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int n, res = 0;
	cin >> n;
	vector<pair<int, int> > v;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		v.push_back(make_pair(a, b));
	}
	sort(v.begin(), v.end(), compare);

	int end = -1;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].first >= end) { // 여태 제일 빨리 끝나는 회의 끝나는 시간보다 지금 시작시간이 뒤일때
			res++;
			end = v[i].second;
		}
	}
	cout << res;
}
반응형

'<algorithm> > 백준' 카테고리의 다른 글

백준 18110 solved.ac c++  (0) 2023.09.17
백준 1987 알파벳 c++  (0) 2023.09.16
백준 9935 문자열 폭발 c++  (0) 2023.09.12
백준 11866 요세푸스 문제 0 c++  (0) 2023.09.11
백준 1018 체스판 다시 칠하기 c++  (0) 2023.09.11
profile

그럴듯한 개발 블로그

@donghyk2

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!