poj-1083-Moving Tables

传送门
题意:一层有400个房间,南北各有200个,要把一张桌子从一个房间移动到另一个房间,需要占用这两个房间之间的所有走廊,每次移动一个桌子所需要的时间是10分钟,给出需要移动的桌子的数据,要求计算出最少需要多少分钟才能把所有桌子移动完

题很简单,但是一定要看题目里面的那个图。有一点需要注意,房间1和2前面是同一个走廊,所以从1移动到2只需要使用一个走廊,而房间2和3前面不是同一个走廊,因此从2移动到3需要占用2个走廊。
基本思路是开辟一个200的数组,表示所有房间前面的走廊被使用的次数,刚开始都为0,如果从m移动到n(其中m

#include <iostream> 
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#define N 202
using namespace std;
int ans[N];
int main(){
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif 
    int i, j, n, T, Max, start, end;
    cin >> T;
    while(T--){
        cin >> n;
        memset(ans, 0, sizeof(ans));
        for (i = 0; i < n; i++){
            cin >> start >> end;
            if (start > end)    swap(start, end);
            for (j = (start-1)/2; j <= (end-1)/2; j++){
                ans[j]++;
            }
        }
        Max = 0;
        for(i = 0; i < 200; i++){
            Max = max(Max, ans[i]);
        }
        cout << Max*10 << endl;
    }
    return 0;
}

你可能感兴趣的:(poj-1083-Moving Tables)