題目描述:
桌上有一疊牌,從第一張牌(即位於頂面的牌)開始從上往下依次編號爲
1∼n。當至少還剩兩張牌時進行以下操作:把第一張牌扔掉,然後把新的第一張放到整疊牌的最後。輸入 n,輸出每次扔掉的牌,以及最後剩下的牌。
輸入描述:
輸入的第一行是一個整數 t(0<t<40),測試數據的個數。隨後 t 行,每一行輸入的一個整數 n(0<n<40),即牌的張數。
輸出描述:
爲每個測試用例單獨輸出一行,該行中依次輸出每次扔掉的牌以及最後剩下的牌,每張牌後跟着一個空格。
輸入:
2
7
4
輸出:
1 3 5 7 4 2 6
1 3 2 4
題意:
字面意思
題解:
用隊列模擬一邊
代碼:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
int t,n;
scanf("%d",&t);
while(t --){
scanf("%d",&n);
queue<int>q;
for(int i = 1; i <= n; i ++){
q.push(i);
}
while(!q.empty()){
printf("%d ",q.front());
q.pop();
q.push(q.front());
q.pop();
}
}
return 0;
}