题意:在一条走廊的两侧各有200个房间,现在给定一些成对的房间相互交换桌子,但是走廊每次只能通过一组搬运, 也就是说如果两个搬运过程有交叉是不能同时搬运的,要依次来,一次搬运10min,问完成所有的搬运的最少用时。
思路:考虑每个房间有多少搬运过程需要经过,我们截取最大的房间经过的次数就可以了,挺锻炼思维的一道题。
代码:
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 405;
int T, N, ans;
int room[maxn];
int main()
{
cin >> T;
while (T--) {
cin >> N;
ans = 0;
memset(room, 0, sizeof(room));
for (int i = 1; i <= N; ++i) {
int x, y;
scanf("%d%d", &x, &y);
if (x > y) swap(x, y);
if(x%2==0) x--;
if(y%2==1) y++;
for(int j = x; j <= y; ++j) {
room[j]++;
ans = max(ans, room[j]);
}
}
cout << ans * 10 << endl;
}
}