hdu1276士兵队列训练问题(队列模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1276

题目大意:balabala快看题,今天小学弟做题说过不去,我便过来做了一下

题目思路:模拟

注意:输入2的时候要输出1 2这个点比较坑!!!还有要读清楚规则。声明两个队列然后模拟一下就好了!!!

代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    queue<int>q1;
    queue<int>q2;
    int t;while(~scanf("%d",&t)){
        while(t--){
        int x;scanf("%d",&x);
        for(int i=1;i<=x;i++){
            q1.push(i);
        }
        while(1){
            if(q1.size()<=3){
                printf("%d",q1.front());q1.pop();
                while(!q1.empty()){
                    printf(" %d",q1.front());
                    q1.pop();
                }
                break;
            }
            int num=1;
            while(!q1.empty()){
                if(num%2==1) {q2.push(q1.front());/*cout<<q1.front()<<endl;*/};
                num++;
                q1.pop();
            }
            if(q2.size()<=3){
                printf("%d",q2.front());q2.pop();
                while(!q2.empty()){
                    printf(" %d",q2.front());
                    q2.pop();
                }
                break;
            }
            num=1;
            while(!q2.empty()){
                if(num%3!=0) q1.push(q2.front());
                num++;
                q2.pop();
            }
        }
        cout<<endl;
        while(!q1.empty()) q1.pop();
        while(!q2.empty()) q2.pop();
        }
    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值