POJ_1083

参考https://blog.csdn.net/lyy289065406/article/details/6642591

利用房间号分割走廊,每条“子走廊”都设置一个计数器,每经过一次+1,最大的次数X10就是答案

#include<iostream>
using namespace std;
#define MAX_ROOM 400
#define TIME_UNIT 10
int ToOdd(int n){
    return n%2==0?n-1:n;
}
int main(){
    int n,nRoad;
    int From,To;
    int *FromId,*ToId;
    int MaxUseCount;
    int a,b;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>nRoad;
        int UseCount[MAX_ROOM] = {0};
        MaxUseCount = 0; 
        FromId = new int[nRoad];
        ToId = new int[nRoad];
        
        for(int j=0;j<nRoad;j++){
            cin>>From>>To;
            
            FromId[j] = From<=To?From:To;
            ToId[j] = To>From?To:From;
            
            FromId[j] = ToOdd(FromId[j]);
            ToId[j] = ToOdd(ToId[j]);
            for(int k=FromId[j];k<=ToId[j];k+=2){
                UseCount[k]++;
                if(MaxUseCount<UseCount[k]){
                    MaxUseCount = UseCount[k];
                }
            }
        }
        cout<<MaxUseCount*10<<endl;
        delete FromId;
        delete ToId;
    } 
    
    return 0;
}

 

上一篇:linux中的SGI(核间中断)IPI_RESCHEDULE详解


下一篇:HDU - 1083 Courses (二分图最大匹配模板)