2012年7月14日土曜日

AOJ Volume20 2013: Osaki

hh:mm:ss で与えられるため秒に統一する。
hh  ->*60*60
mm->*60
ss  
その時間に出発した電車、到着した電車の数をカウントする。
その時間にどれだけの電車が走っているかをカウントし、その最大値が答えになる。



 /*********************************
* 2012/0714                      *
* AOJ_Volume20_2013              *
* Osaki                          *
* crane                          *
**********************************/
#include<iostream>
#include<cstdio>
using namespace std;

#define MAX_N 24*60*60
int field[MAX_N];


int main(){
    int n;
    while(cin >> n, n){
        for(int i=0; i<MAX_N; i++)
            field[i] = 0;

        int h1,m1,s1,h2,m2,s2;
        for(int i=0; i<n; i++){
            scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
            int t1 = (h1 * 3600) + (m1 * 60) + s1;//秒に統一
            int t2 = (h2 * 3600) + (m2 * 60) + s2;
            field[t1]++;    //その時間に出発した電車をカウント
            field[t2]--;    //その時間に到着した電車をカウント
        }
       
        int m_count=0, count=0;
        for(int i=0; i<MAX_N; i++){//その時間に走っている車両数の最大値が答えになる。
            count += field[i];
            m_count = max(m_count, count);
        }
        cout << m_count << endl;       
    }
    return 0;
}


0 件のコメント:

コメントを投稿