NetEase Youdao programming push in the 2017 title 1

Subject description:

Shuffle is very common in life, and now need to write a program to simulate the process of shuffling. Now need to wash 2n cards, from top to bottom is the first one, the first two, the first three have been the first to 2n sheets. First, we put 2n cards into two piles, one of the left hand to the n-th (upper half stack), right hand holding the first sheet n + 1 to 2n-th sheet (the second half stack). Then began shuffling process, right down to the last card, then put down his left hand last card, then put down the right hand penultimate card, then down the left hand reciprocal second card until the last drop left hand the first card. Then merge the cards up on it. 6 for example, cards, card sequence is the beginning of 1, 2, 3, 4, 5, 6. First divided into two groups, a left hand, 2, 3; right hand 4, 5, 6. In the shuffling process in order to lay down the 6, 3, 5, 2, 4, 1. After these six cards synthesize a set of cards once again, we look at this set of cards in accordance with the order from top to bottom, it becomes a sequence of 1, 4, 2, 5, 3, 6. Sequence from the top after the original is now given a card group, the k shuffle the deck output.

Input Description:
The first line of a number of T (T ≤ 100), represents the number of data sets. For each test, the first line of the two numbers n, k (1 ≤ n, k ≤ 100), the next line has 2n number a1, a2, ..., a2n ( 1 ≤ ai ≤ 1000000000). It represents the sequence of the original deck from top to bottom.

Description Output:
For each test, an output line, the final sequence. Separated by spaces between the numbers, not the end of the line output extra spaces.

Examples 1 Input:
3,311,234,563,212,345,622 1 1 1 1

Output Example 1:
1,425,361,543,261,111

Explain: 3 indicates three groups of data, respectively. 1 3 3. 4. 5. 6. 1 2
3 2 3 2. 1. 4. 5. 6
2 2. 1. 1. 1. 1
data of the first number in each group is n, the second data is k, back It is 2n cards


// later found by his example to the pit, in fact, line by line data entry

Problem-solving ideas:

  Option One:

    The input data shuffling in accordance with the rules of the k-th wash

  Option II:

    The input data is stored k times washing position by shuffling rules, which determine the final position

Code:

  

 1 #include <iostream>
 2 #include <vector>
 3 #include <string>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int group;
 9     cin >> group;
10 
11     vector<int> Res;
12     while (group--)
13     {
14         int n, k;
15         cin >> n >> k;
16 
17         //方法一:
18         // Vector <int> V1, V2;
 . 19          // Vector <int> VV (n-2 *);
 20 is          // for (int I = 0; I <* n-2; I ++)
 21 is          // {
 22 is          / /     int a;
 23 is          //     CIN >> a;
 24          //     IF (I <n-)
 25          //         v1.push_back (a); // left set
 26 is          //     the else
 27          //         v2.push_back (a) ; // right set
 28          // }
 29          // the while (K--)
 30          // {
 31 is          //    for (int nn = 0, mm = 0; nn < n * 2; ++mm)
32         //    {
33         //        vv[nn++] = v1[mm];
34         //        vv[nn++] = v2[mm];
35         //    }
36         //    v1.assign(vv.begin(), vv.begin() + n);
37         //    v2.assign(vv.begin() + n, vv.end());
38         //}
39 
40         //方法二:
41         vector<int>vv(2 * n);
42         int a;
43         for (int i = 0; i < 2 * n; ++i)
44         {
45             cin >> a;
46             int tmp = i + 1;
47             for (int j = 0; j < k; ++j)
48                 if (tmp <= n)
49                     tmp = 2 * tmp - 1;
50                 else
51                     tmp = 2 * (tmp - n);
52             vv[tmp - 1] = a;
53         }
54 
55         for (auto b : vv)
56             cout << b << ' ';
57         cout << endl;
58     }
59     return 0;
60 
61 }

 

Guess you like

Origin www.cnblogs.com/zzw1024/p/10983882.html