题目描述
桌上有一叠牌,从第一张牌(即位于顶面的牌)开始从上往下依次编号1~n。当至少还剩1张牌时进行以下操作:
1、把第一张牌扔掉
2、然后把新的第一张牌放到整叠牌的最后。
输入n,输出每次扔掉的牌。
输入格式
输入包括一个整数n表示有n张牌
输出格式
输出每次扔掉的牌
样例输入
7
样例输出
1 3 5 7 4 2 6
提示
(1<=n<=50000)
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
int w[300105];
int b[2102105];
const int maxx = 40010;
int n,m,r,k,t,num,now,p;
const double pi=acos(-1.0);
queue <int> e;//初始化栈
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1 ; i <= n ; i ++)//初始化队列
{
e.push(i);//先存入队列
}
while(e.empty() == 0)//如果队列不为空
{
cout << e.front() << " ";//输出队首
e.pop();//去除队首
int num1 = e.front();//新队首
e.push(num1);//将新的队首再次推入队列
e.pop();//删除新队首
}
return 0;
}