zoukankan      html  css  js  c++  java
  • 201709-2公共钥匙盒


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

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

  • 相关阅读:
    UVA 558 Wormholes
    HDU 1565 方格取数(1)
    poj2607
    poj2552
    poj2491
    poj2502
    poj2613
    .NET Framework 4 与 .NET Framework 4 Client Profile的区别与联系
    .Net Framework 4.0 和 2.0/3.0/3.5
    企业IT系统
  • 原文地址:https://www.cnblogs.com/WuDie/p/11386277.html
Copyright © 2011-2022 走看看