

3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
10 20 30
解题思路:贪心,考虑每次的最优解,则对面的两房间共同拥有它们所对应的区域,每次交错,都会产生一次冲突,就代表他们不能再同一次搬运,考虑到多次转移的交错的区域,最大交错的次数就代表了最小的搬运次数。
AC代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int room[205];
int main(){
// freopen("in.txt", "r", stdin);
int t, n, x, y;
scanf("%d", &t);
while(t--){
memset(room, 0, sizeof(room));
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d%d", &x, &y);
if(x > y) swap(x, y); //防止起始房间大于终止房间
for(int i=(x+1)/2; i<=(y+1)/2; i++){
room[i] ++; //对应区域的交错次数增加
}
}
int ans = 0;
for(int i=1; i<=201; i++){
if(ans < room[i]) ans = room[i];
}
printf("%d\n", ans*10);
}
return 0;
}
原文:http://blog.csdn.net/u013446688/article/details/41133351