201709-2公共钥匙盒

1554711-20190820231741729-1431279697.png
1554711-20190820231817179-461746831.png

#include<iostream>
#include<queue>
using namespace std;

struct _node {
    int num;//钥匙编号
    char op;//操作 g:取钥匙 r还钥匙
    int time;//某时间
    bool operator <(_node a) const
    {
        if (time != a.time)
            return time > a.time;
        else
        {
            if (op != a.op)
                return op < a.op;
            else
            {
                return num > a.num;
            }
        }
    }

};

priority_queue <_node> p;

int hook[1001];


int main()
{
    int n, k;
    cin >> n >> k;
    int w, s, c;
    _node t;

    
    for (int i = 1; i <= n; i++)
    {
        hook[i] = i;
    }


    for (int i = 1; i <= k; i++)
    {
        cin >> w >> s >> c;
        t.num = w;
        t.op = 'g';
        t.time = s;
        p.push(t);


        t.time =s + c;
        t.op = 'r';
        p.push(t);
    }
    
    while (!p.empty())
    {
        t = p.top();
        p.pop();

        if (t.op == 'g')
        {
            for (int i = 1; i <= n; i++)
            {
                if (t.num == hook[i])
                {
                    hook[i] = 0;
                    break;
                }
            }
        }
        else
        {
            for(int i=1;i<=n;i++)
                if (hook[i] == 0)
                {
                    hook[i] = t.num; 
                    break;
                }
        }

    }

    for (int i = 1; i <= n; i++)
    {
        cout << hook[i];
        if (i != n)
            cout << " ";
    }
    return 0;
}

抄的,真难,别人做的真简单,多看看

转载于:https://www.cnblogs.com/WuDie/p/11386277.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值