• 看病


    本来看着挺简单结果写完了怎么也调不对调了半个小时

    很明显直接用优先队列直接模拟就好了。(没啥好说的)但是就是写不对

    刚开始发现记不住 priority 怎么写,后来发现自己记不住重载运算符怎么写,再后来发现忘了优先队列怎么用...

    就当是复习一遍这堆东西了吧。

    #include<bits/stdc++.h>
    using namespace std;
    int n;
    struct node{
    	int w;
    	string nam;
    	bool operator<(const node& x) const{//大根堆
    		return w<x.w;
    	}
    };
    priority_queue<node>q;
    int main()
    {
    	scanf("%d",&n); 
    	for(int i=1;i<=n;i++)
    	{
    		string op;
    		cin>>op;
    		if(op[1]=='o')
    		{
    			if(q.empty()) cout<<"none"<<endl;//一定要先判断是否为空
    			else
    			{
    				cout<<q.top().nam<<" "<<q.top().w<<endl;//让最严重的病人看病
    				q.pop();//别忘了弹出
    			}
    		}
    		else
    		{
    			node a;
    			cin>>a.nam>>a.w;
    			q.push(a);//加入队列
    		}
    	}
    	return 0;
    }//qwq
    
  • 相关阅读:
    Labeling Balls
    Following Orders
    Frame Stacking
    Window Pains
    Sort it all out
    Ferry Loading||
    今年暑假不AC
    xcode10 出现 框架 或者 pod 出错
    网络请求 步骤
    swift UIAlertController使用 UIAlertController的宽度 为270
  • 原文地址:https://www.cnblogs.com/ying-xue/p/kan-bing.html
Copyright © 2020-2023  润新知