题意:在一个走廊两边都有对称分布的连续房间,现在有n张桌子需要从a移动到b房间。每次移动需要10分钟,
但是如果两次移动中需要经过相同的走廊位置,则不能同时进行,需要分开移动。最后求最少需要多长时间移动完所有的桌子。
析:这应该是一个贪心算法,时间尽量少,但是在一走廊如果相遇,必然是要分开的,所以说,我们只要统计,
统计在每个走廊的相遇的次数,然后再取最大值,如果最大值都成立了,那么其他的也会成立(想一下,为什么)。
你想一下,假设有另一个走廊,次数比它少,即使他们的桌子不相同,而其他那些可以在其他时间搬运过去,也不是超过最多次数。
代码如下:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 200 + 5;
int cnt[maxn];
int main(){
int n, T, a, b; cin >> T;
while(T--){
scanf("%d", &n);
memset(cnt, 0, sizeof(cnt));
for(int i = 0; i < n; ++i){
scanf("%d %d", &a, &b);
int minn = min(a, b); ++minn;
int m = max(a, b); ++m;
for(int j = minn/2; j <= m/2; ++j)
++cnt[j];
}
int m = 0;
for(int i = 0; i < maxn; ++i)
m = max(m, cnt[i]);
printf("%d0
", m);
}
return 0;
}