huh0918   1년 전

도저히 어디가 틀린지가.. 

회의끝나는 시간 순으로 정렬해서 순서대로 넣었습니다.

dlbae9613   1년 전

반례입니다.

7
3 10
2 2
1 3
2 2
9 10
4 9
2 2

정답 : 5

출력 : 6

huh0918   1년 전

감사합니다 해당 반례를 해결했는데요 여전히 오답이 나오네요 혹시 이것도 한번만 봐주실 수 있으실까요? 감사합니다!

#include
#include
#include
using namespace std;

class Meet
{
public:
int st;
int end;
Meet(int a, int b)
{
st = a; end = b;
}
bool operator<(const Meet& a) const
{
if ( this->end < a.end)
return true;
else
return false;
}
void Print(){
cout << st << "->"<< end << endl;
}
};

int n;
vector meetings;
vector schedule;

int main()
{
cin >> n;

int from, to;
while(n--)
{
cin >> from >> to;
meetings.push_back(Meet(from, to));
}



sort(meetings.begin(), meetings.end());



schedule.push_back(meetings.front());
vector::iterator iter;
for(iter = meetings.begin() +1 ; iter != meetings.end(); iter++)
{
if(schedule.back().end <= iter ->st)
schedule.push_back(*iter);
}




cout << schedule.size() << endl;
}

댓글을 작성하려면 로그인해야 합니다.