(优先队列)hdu1509 Windows Message Queue

偏执的太偏执、 2022-03-17 08:58 304阅读 0赞

题目链接:(优先队列)hdu1509 Windows Message Queue

  1. #include<iostream>
  2. #include<queue>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<cstring>
  6. #include<string>
  7. using namespace std;
  8. const int maxn = 2010;
  9. const int INF=0x3f3f3f3f;
  10. typedef struct Node{
  11. char name[100]; //不知道为什么,用string类型放进优先队列里总是出错
  12. int w,c,id;
  13. bool operator < (const Node &A)const{
  14. if(c!=A.c) return c>A.c;
  15. return id>A.id;
  16. }
  17. }Node;
  18. Node tmp;
  19. int main()
  20. {
  21. priority_queue<Node> pq;
  22. char s[5];
  23. int r=0;
  24. while(~scanf("%s",s)){
  25. if(strcmp(s,"GET")==0){
  26. if(pq.empty()){
  27. printf("EMPTY QUEUE!\n");
  28. }else{
  29. tmp=pq.top();
  30. printf("%s %d\n",tmp.name,tmp.w);
  31. pq.pop();
  32. }
  33. }else{
  34. scanf("%s%d%d",tmp.name,&tmp.w,&tmp.c);
  35. tmp.id=r;
  36. r++;
  37. pq.push(tmp);
  38. }
  39. }
  40. return 0;
  41. }

发表评论

表情:
评论列表 (有 0 条评论,304人围观)

还没有评论,来说两句吧...

相关阅读

    相关 优先队列(priority_queue)

    优先队列:优先级最高的先出队。 队列和排序的完美结合,可以存储数据,还可以把这些数据按设定的规则进行排序。 每次的push和pop操作,优先队列都会动态调整,把优先级最