12694 Meeting Room Arrangement

題目:http://luckycat.kshs.kh.edu.tw/homework/q12694.htm
觀念:Greedy
難度:luckycat ★★

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int T, N;
struct Meeting{
    int s, e;    
}meeting[25];

bool cmp( Meeting A, Meeting B ){
    return A.e < B.e;    
}

int main(){
    int s, e;
    int ts, te;

    cin >> T;
    while ( T-- ){
        N = 0;
        while ( cin >> ts >> te ){
            if ( ts == 0 && te == 0 ) break;
            meeting[N].s = ts;
            meeting[N].e = te;
            N++;
        }

        sort( meeting, meeting+N , cmp );

        int ans = 0, lastUsedTime = 0;

        for ( int i = 0 ; i < N ; i++ )
            if ( meeting[i].s >= lastUsedTime ){
                ans++;
                lastUsedTime = meeting[i].e;
            }

        cout << ans << endl;

    }

    return 0;    
}

results matching ""

    No results matching ""