Moving Tables
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 51 Accepted Submission(s) : 24
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description

The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.

For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.
Input
Output
Sample Input
3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
Sample Output
10
20
30
题目大意:人们从不同的房间搬桌子到不同的房间,对于每个人来说不管路多长都只用十分钟搬完。计算所有人都搬完桌子共用多少时间。
解题思路:如果人们搬桌子的路径没有交叉的话,那总时间就是十分钟,如果有路径被公用的话,并且其中有一段被共用的次数最多,那么该段路径每有一个人经过就得用十分钟,所以总时间便是最繁忙的那段路径的次数乘十即为总时间。
代码:
#include <iostream>
using namespace std;
int main()
{
int m,n,i,j,k,l,s,p;
int b[500];
cin>>n;
while(n--)
{
memset(b,0,sizeof(b));
cin>>m;
for(i=0;i<m;i++)
{
cin>>s>>p;
if(s>p)
swap(s,p);
s=(s+1)/2;//因为房间是两个相对的所以只找一半就可以了
p=(p+1)/2;
for(j=s;j<=p;j++)
{
b[j]++;//记录每段路径的繁忙度
}
}
int max=0;//找最繁忙的路径
for(i=1;i<=202;i++)
{
if(b[i]>max)
{
max=b[i];
}
}
cout<<max*10<<endl;
}
return 0;
}