[贪心]HDU1085 Moving Tables

D - Moving Tables
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit

Status
Description
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.

这里写图片描述

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.

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

相对门的两个房间占用同一处走廊,所以例如有1——3和4——6移动方式时,它们是共享了同一段走廊的,即3号房间门前的走廊。

分析过程有如下图所示
这里写图片描述

所以当左端起点为偶数时,要将其中左端的起点再向左移动一位,
当右端终点为奇数时,要将右端的终点在向右移动一位。

计算每一个位置上最大走过的次数。

#include <cstdio>
#include <cstring>
#include<algorithm>

#define MAXN 505
using namespace std;

int main()
{
    int Count[MAXN];
    int i, j, testNum, n, L, R;
    scanf("%d", &testNum);
    while (testNum-- != 0)
    {
        scanf("%d", &n);
        memset(Count, 0, sizeof(Count));
        for (i = 0; i < n; i++)
        {
            scanf("%d %d", &L, &R);
            if (L > R) swap(L,R);
            if (L % 2 == 0)
                Count[L-1]++;
            if (R % 2 == 1)
                Count[R+1]++;
            for (j = L; j <= R; j++)
                Count[j]++;
        }
        printf("%d\n", *max_element(Count,Count+MAXN)*10);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值