회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
예제는 일단 맞게 뜨는데 어디가 틀렸는지 모르겠습니다....
1931번 - 회의실 배정
elixter
5년 전
0
여러가지를 해봤는데 다 답은 맞게나오는 것 같습니다만... 혹시 예외가 어떤게 있을까요????
#include <iostream> #include <algorithm> using namespace std; class Node { public: int start; // Conference start time int end; // Conference end time int duration; public: Node() : start(0), end(0), duration(0) {} // Default constructor public: bool operator<(Node &a) { if (start < a.start) return true; else if (start == a.start && duration < a.duration) return true; else return false; } }; int roomAllocate(int n, Node confs[]); int main() { int N; // # of Conference cin >> N; Node * conf = new Node[N + 1]; // input data for (int i = 1; i <= N; i++) { cin >> conf[i].start; cin >> conf[i].end; conf[i].duration = conf[i].end - conf[i].start; } sort(conf, conf + N); // sorting increasing order cout << roomAllocate(N, conf); return 0; } int roomAllocate(int n, Node confs[]) { int *DP = new int[n + 1]; // DP[i] is number of conference can be allocated when serch i th confernce int i; int alloc = 0; DP[0] = 0; // if i th conference start time is before previous selected conference, check next conference // else compare i th conference's end time and i + 1th start time // if i th conference's end time is after i + 1 th start time // compare duration and select short one. for (i = 1; i <= n; i++) { if (i == n) { if (confs[DP[i - 1]].end > confs[i].start) DP[i] = DP[i - 1]; else { DP[i] = i; alloc++; } } else { if (confs[DP[i - 1]].end > confs[i].start) DP[i] = DP[i - 1]; else { if (confs[i].end <= confs[i + 1].start) { DP[i] = i; alloc++; } else { if (confs[i].duration <= confs[i + 1].duration) { DP[i] = i; alloc++; } else DP[i] = DP[i - 1]; } } } } return alloc; }
댓글을 작성하려면
로그인
해야 합니다.
elixter 5년 전
여러가지를 해봤는데 다 답은 맞게나오는 것 같습니다만... 혹시 예외가 어떤게 있을까요????