题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1050

题目描述

The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.
http://acm.hdu.edu.cn/data/images/1050-1.gif

The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.
http://acm.hdu.edu.cn/data/images/1050-2.gif

For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.

思路

这题就是求最大重叠区间数量。。。

AC代码

/*************************************************************************
    > File Name: 1050.cpp
      > Author: Netcan
      > Blog: http://www.netcan.xyz
      > Mail: 1469709759@qq.com
      > Created Time: Thu 04 Jun 2015 11:31:35 AM CST
 ************************************************************************/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <sstream>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <stack>
#include <set>
#include <numeric>
#include <utility>
#include <cstring>
using namespace std;

int main()
{
#ifdef Oj
    freopen("1050.in", "r", stdin);
#endif
    int T;
    cin >> T;
    int n;
    int P[200]; // P为记录每个走廊占用次数,从左往右数一共200个走廊
    while(T--) {
        cin >> n;
        int s, e;
        int maxt=0; // maxt为最大重叠房间区间数
        memset(P, 0, sizeof(P));
        for (int i = 0; i < n; ++i) {
            cin >> s >> e;
            s = (s-1)/2; // 因为房间分为两层所以要对半。例如1->4只占两个走廊位置。
            e = (e-1)/2;
            if(s > e)
                swap(s, e);
            for (int i = s; i <= e; ++i) {
                ++P[i]; // 记录占用次数。
                maxt = max(maxt, P[i]);
            }
        }
        cout << maxt*10 << endl;
    }

    return 0;
}