题意:在一个走廊里面移桌子,但是走廊很窄,一次只能通过一把椅子。
如果移动的路线没有相交,可以同时进行。问你最少的时间是多少?
思路:可以将房间移到同一边,即(1,2)(3,4)(5,6)。。。。将这两个相对的房间变成同一个房间,然后用一个数组去存储每一个房间被经过的次数,最大值就是最少的时间。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 205
using namespace std;
int main()
{
int t,n;
int cnt[N];
scanf("%d",&t);
while(t--)
{
memset(cnt,0,sizeof(cnt));
scanf("%d",&n);
int maxn=-1,from,to;
while(n--)
{
scanf("%d%d",&from,&to);
if(from>to)
swap(from,to);
from=(from+1)/2;
to=(to+1)/2;
for(int i=from;i<=to;i++){
cnt[i]++;//从from~to沿途经过的点都加一次
if(cnt[i]>maxn)
maxn=cnt[i];
}
}
printf("%d\n",maxn*10);
}
return 0;
}