【HDOJ】2319 Card Trick

水题,STL双端队列。

 1 /* 2319 */
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <deque>
 6 #include <algorithm>
 7 using namespace std;
 8 
 9 int main() {
10     int n, t;
11     int i, j, k;
12     deque<int> Q;
13     
14     #ifndef ONLINE_JUDGE
15         freopen("data.in", "r", stdin);
16     #endif
17     
18     scanf("%d", &t);
19     while (t--) {
20         scanf("%d", &n);
21         Q.push_front(n);
22         for (i=n-1; i>=1; --i) {
23             Q.push_front(i);
24             for (j=0; j<i; ++j) {
25                 k = Q.back();
26                 Q.pop_back();
27                 Q.push_front(k);
28             }
29         }
30         k = Q.front();
31         Q.pop_front();
32         printf("%d", k);
33         while (!Q.empty()) {
34             k = Q.front();
35             Q.pop_front();
36             printf(" %d", k);
37         }
38         printf("
");
39     }
40     
41     return 0;
42 }
原文地址:https://www.cnblogs.com/bombe1013/p/4269520.html