[IT]/백준
[백준] 1931번 회의실 배정
working_hard
2019. 6. 2. 19:44
728x90
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
class Meeting {
public:
int begin, end;
};
bool compare(const Meeting &u, const Meeting &v) {
if (u.end == v.end) {
return u.begin < v.begin;
}
else {
return u.end < v.end;
}
}
int main() {
int n;
cin >> n;
vector<Meeting> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].begin >> a[i].end;
}
sort(a.begin(), a.end(), compare);
int now = 0;
int ans = 0;
for (int i = 0; i < a.size(); i++) {
if (now <= a[i].begin) {
now = a[i].end;
ans += 1;
}
}
cout << ans << endl;
return 0;
}
왜 이렇게 풀었는지 아직 감이 잘 안잡힌다... 특히 for문 안의 내용이 감이 전혀 없다. now 가 작으면 end를 붙여주고 1개 더하라는게 무슨말일까