程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> nyoj714 Card Trick(第六屆河南省程序設計大賽)

nyoj714 Card Trick(第六屆河南省程序設計大賽)

編輯:關於C++
題目714題目信息運行結果本題排行討論區

Card Trick

時間限制:1000ms | 內存限制:65535KB 難度:3

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

描述
  1. 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 thenth and last card turns out to be thenof Spades.

    This impressive trick works if the magician knows how to arrange the cards beforehand (and knows how to give a false shuffle). Your program has to determine the initial order of the cards for 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

     

     

    題意:給你n張牌,分別是1-n

    第一次把最上面1張放到最下面,亮出當前最上面的牌 使其為1

    第二次把最上面2張放到最下面,亮出當前最上面的牌 使其為2

    第三次把最上面3張放到最下面,亮出當前最上面的牌 使其為3

    ..............

    模擬一下過程就好了 當然如果你對時間更苛刻 由於最多只有13張牌 可以把結果存在一個數組

     

     

    #include 
    #include 
    using namespace std;
    int main()
    {
    	int ncase;
    	int order[13];
    	scanf("%d",&ncase);
    	while(ncase--)
    	{
    		int n;
    		scanf("%d",&n);
    		queues;
    		for(int i=0;i

     

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved