题目链接: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();
}
}
}