Moving Tables HDU - 1050 贪心

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

在这里插入图片描述

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.

睡前 水题 结果wa了一晚上。。。
难受 看错了题

啊卧槽终于过了 一道贪心水题 出了各种各样的小错误 着实让人崩溃 审题还是不仔细 总是出各种各样的错误
思路 : 将房间号转化为在走廊的序号 按终止位置由小到大排序 然后遍历每一次移动 维护数组 : 若在当前队列可以排进去 就将结尾数组更新为当前移动结尾 若已有的队列排不进去 就新开一个 跟新完后按降序排列 以便每次都可以取得最优结论
wa:
1.输入的移动可能会有倒着的。。。
2.移动应该按结尾升序排列 结尾数组应该按降序排列 以便每次都可以取得最优结论
3.输入的移动应该转化为在走廊中的移动
代码:

#include<bits/stdc++.h>
using namespace std;

struct T{
    int s, e;
};

bool cmp(T a, T b){
    return a.e < b.e;
}

bool cmp2(int a, int b){
    return a > b;
}
int main(){
    int N;
    cin >> N;
    while(N--){
        int n;
        cin >> n;
        T t[n];
        int ss[n], ee[n];
        for(int i = 0; i < n; i++){
            cin >> t[i].s >> t[i].e;
            if(t[i].s > t[i].e){
                int a = t[i].s; t[i].s = t[i].e; t[i].e = a;
            }
            t[i].s = (t[i].s + 1)/2;
            t[i].e = (t[i].e + 1)/2;
        }
        sort(t, t+n, cmp);

        int k = 1;
        ee[0] = t[0].e;

        for(int i = 1; i < n; i++){
            int flag = 0;
            for(int j = 0; j < k; j++){
                if(t[i].s > ee[j]){
                    ee[j] = t[i].e;
                    sort(ee, ee+k, cmp2);
                    flag = 1;
                    break;
                }
            }
            if(flag == 0){
                ee[k++] = t[i].e;
                sort(ee, ee+k, cmp2);
                //cout << ee[k-1] <<"===" <<endl;
            }
        }
        cout << k*10 << endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值