HDOJMoving table


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;
}


 

学习总结:好奇妙的转化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值