zoj - 2724 - Windows Message Queue
题意:PUT为存入,GET为取队头查询,不停地存入与取队头元素,输出相应的信息即可。
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1724
——>>之前见题目的通过率只有26.65%,又赶时间,早早地跳过了这题,刚刚看了下,用优先队列一试,原来是那么水的……无语
#include <iostream> #include <queue> using namespace std; struct node //定义结点数据类型 { string name; int val; int weight; }; bool operator < (node e1, node e2) //定义优先队列的排序方式,权值小的在前面 { return e1.weight > e2.weight; } int main() { string type; //输入的第一个单词,要么是"GET",要么是"PUT" priority_queue<node> qu; //程序的核心,优先队列 while(cin>>type) { if(type == "GET") //当为读取数据的时候 { if(qu.empty()) cout<<"EMPTY QUEUE!"<<endl; //队空时 else //队不空时 { cout<<qu.top().name<<" "<<qu.top().val<<endl; qu.pop(); } } else //当为存取数据的时候 { node newnode; cin>>newnode.name>>newnode.val>>newnode.weight; //入列 qu.push(newnode); } } return 0; }