您的位置:首页 > 运维架构

Uva 6440 - Emergency Handling 多个优先队列维护

2013-12-01 22:40 369 查看
题意:

再一个二维平面内,不断的有射线插入(1<=N<=100000)..同时也会在某些x处询问这些射线中最大的y值...请输出这些y值...

题解:

突破口在题目给出了斜率范围是[1,100]的整数.. 所以可以构造100个优先队列..优先级是在这个斜率下..y值大...那么每次要么就是往100个中某个优先队列丢入一个线..要么是输出..找出这100个中..栈顶y最大的..然后将其弹栈...

Program:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string.h>
using namespace std;
typedef long long ll;
priority_queue<int> Q[102];
int main()
{
      int C,cases,n,t,s,r,num,w,temp,h,data;
      char c; 
      scanf("%d",&C);
      for (cases=1;cases<=C;cases++)
      {
              scanf("%d",&n);
              for (r=0;r<=100;r++)
                 while (Q[r].size()) Q[r].pop();
              printf("Case #%d:\n",cases);
              num=0;
              while (n--)
              {
                      do
                      {
                            c=getchar();
                      }while (c!='P' && c!='A');
                      if (c=='P')
                      {
                            scanf("%d%d%d",&t,&s,&r);
                            s-=t*r;
                            Q[r].push(s);
                      }else
                      {
                            data=-(1<<30);
                            scanf("%d",&t);
                            for (r=0;r<=100;r++)
                               if (Q[r].size())
                               {
                                      h=Q[r].top();
                                      temp=h+t*r;
                                      if (temp>=data)
                                      {
                                             data=temp;
                                             w=r;
                                      }
                               }
                            h=Q[w].top(),Q[w].pop();
                            printf("%d %d\n",h+t*w,w);
                      }
              }
      }
      return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: