码迷,mamicode.com
首页 > 其他好文 > 详细

201709-2公共钥匙盒

时间:2019-08-21 00:14:57      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:std   mamicode   const   nod   ons   priority   ios   stream   char   

技术图片
技术图片

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

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

201709-2公共钥匙盒

标签:std   mamicode   const   nod   ons   priority   ios   stream   char   

原文地址:https://www.cnblogs.com/WuDie/p/11386277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!