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
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
Output
The output should contain the minimum time in minutes to complete the moving, one per line.
#include <iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int a[201];
int n,i,T,s,t;
scanf("%d",&T);
while(T--)
{
int max=0;
memset(a,0,sizeof(a));
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&s,&t);
if(s>t)
{
s^=t;
t^=s;
s^=t;
}
s=(s+1)/2;//由于房间是奇偶分开的,所以先把他们换成连续的自然数,即n=(n+1)/2.这样对门的就变成一个编号了---很神奇
t=(t+1)/2;
for(i=s; i<=t; i++)
{
++a[i];
if(a[i]>max)
max=a[i];
}
}
printf("%d\n",max*10);
}
return 0;
}
HDOJMoving table
最新推荐文章于 2021-08-26 17:00:06 发布