2012.6辽宁省赛 Problem F

自己模拟了,没有交过,不知道是否正确。

#include<iostream>
#include<queue>
#include<stack>
#define max 10
using namespace std;
int main()
{
    queue<int>player1;
    queue<int>player2;
    stack<int>table;
    bool ontable[max];
    int n,m,times,i,data,temp;
    while(cin>>n>>m>>times)
    {
        for(i=0;i<n;i++)
        {
            cin>>data;
            player1.push(data);
        }
        for(i=0;i<m;i++)
        {
            cin>>data;
            player2.push(data);
        }
        for(i=0;i<times;i++)
        {
            if(i%2==0)
            {
                if(!ontable[player1.front()])
                {
                    ontable[player1.front()]=1;
                    table.push(player1.front());
                    player1.pop();
                }
                else
                {
                    temp=player1.front();
                    player1.push(temp);
                    player1.pop();
                    while(table.top()!=temp)
                    {
                        player1.push(table.top());
                        table.pop();
                    }
                    player1.push(table.top());
                    table.pop();
                    ontable[player1.front()]=0;
                }
            }
            else
            {
                if(!ontable[player2.front()])
                {
                    ontable[player2.front()]=1;
                    table.push(player2.front());
                    player2.pop();
                }
                else
                {
                    temp=player2.front();
                    player2.push(temp);
                    player2.pop();
                    while(table.top()!=temp)
                    {
                        cout<<player2.back()<<endl;
                        player2.push(table.top());
                        table.pop();
                    }
                    player2.push(table.top());
                    table.pop();
                    ontable[player2.front()]=0;
                }
            }
        }
        cout<<player1.size()<<" "<<player2.size()<<endl;
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值