hdoj5818【模拟】

26 篇文章 0 订阅

2016 Multi-University Training Contest 7 1010

思路:

我相信T的绝对是直接根据题目意思来了。

正确的一点小转变,比较一下那个队列小,然后把小的给大的,每次都这样就好了。

来想想,觉得这样好像也不对啊,我两个队列都push进去5e4,那么merge操作,还是1e4啊,但是说自己年轻就是连复杂度都不会计算,这个1e4只有一次啊...

年轻啊...七夕节快乐...

<pre name="code" class="cpp">#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
#define MAX 100010
#define ll long long
#define mod 10000007
int n,m;

struct node
{
    int num;
    int pri;
    bool operator < (const node &a)const
    {
        return pri<a.pri;
    }
};

priority_queue<node> P[3];

int main()
{
    int i;
    int t=0;
    while(~scanf("%d",&n)&&n)
    {
        while(!P[0].empty()) P[0].pop();
        while(!P[1].empty()) P[1].pop();

        printf("Case #%d:\n",++t);
        char s[11],x[2],y[2];
        int a,b,bb;
        a=0;
        b=1;
        node now;
        for(i=0;i<n;i++)
        {
            scanf("%s",s);
            if(s[1]=='o')
            {
                scanf("%s",x);
                if(x[0]=='A')
                {
                    bb=P[a].top().num;
                    printf("%d\n",bb);
                    P[a].pop();
                }
                else
                {
                    bb=P[b].top().num;
                    printf("%d\n",bb);
                    P[b].pop();
                }
            }
            else if(s[1]=='u')
            {
                scanf("%s%d",x,&bb);
                now.num=bb;
                now.pri=i;
                if(x[0]=='A')
                    P[a].push(now);
                else
                    P[b].push(now);
            }
            else
            {
                scanf("%s%s",x,y);
                if(P[a].size()>P[b].size())
                {
                    while(!P[b].empty())
                    {
                        P[a].push(P[b].top());
                        P[b].pop();
                    }
                    if(x[0]!='A')
                    {
                        int temp;
                        temp=a;
                        a=b;
                        b=temp;
                    }
                }
                else
                {
                    while(!P[a].empty())
                    {
                        P[b].push(P[a].top());
                        P[a].pop();
                    }
                    if(x[0]=='A')
                    {
                        int temp;
                        temp=a;
                        a=b;
                        b=temp;
                    }
                }
            }
        }
    }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值