日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

CardTrick

發布時間:2025/3/16 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CardTrick 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

The magician shuffles a smallpack of cards, holds it face down and performs the following procedure:

  • The top card is moved to the bottom of the pack. The new top card is dealt face up onto the table. It is the Ace of Spades.
  • Two cards are moved one at a time from the top to the bottom. The next card is dealt face up onto the table. It is the Two of Spades.
  • Three cards are moved one at a time…
  • This goes on until the?nth and last card turns out to be the?n?of Spades.
  • This impressive trick works ifthe magician knows how to arrange the cards beforehand (and knows how to give afalse shuffle). Your program has to determine the initial order of the cardsfor a given number of cards, 1 ≤ n ≤ 13.

    輸入

    On the first line of the input is a single positive integer k, telling the number of test cases to follow. 1 ≤ k ≤ 10 Each case consists of one line containing the integer n. 1 ≤ n ≤ 13

    輸出

    For each test case, output a line with the correct permutation of the values 1 to n, space separated. The first number showing the top card of the pack, etc…

    樣例輸入

    2 4 5

    樣例輸出

    2 1 4 3 3 1 4 5 2

    AC代碼:

    #include<iostream> #include<cstdio> #include<queue> using namespace std; int main() {int K,n;int i,j,k;int a[15],b[15];while(cin>>K)while(K--){cin>>n;queue<int>qt;for(i=1;i<=n;i++)qt.push(i);for(i=1;i<=n;i++){j=i;while(j--){k=qt.front();qt.pop();qt.push(k);}a[i]=qt.front();qt.pop();}for(i=1;i<=n;i++)b[a[i]]=i;for(i=1;i<n;i++)cout<<b[i]<<" ";cout<<b[i]<<endl;}return 0; }





    總結

    以上是生活随笔為你收集整理的CardTrick的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。