POJ 1068

采用的模拟的方法,应该会有更好的数学上的办法吧~~~

 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4 #include <cstdlib>
 5 #include <cmath>
 6 #include <map>
 7 #include <stack>
 8 #include <algorithm>
 9 #include <list>
10 #include <ctime>
11 #include <set>
12 #include <queue>
13 using namespace std;
14 
15 int main() {
16     int n, m;
17     cin >> n;
18     for (int i = 0; i < n; i++) {
19         cin >> m;
20         vector<int> data(m, 0);
21         vector<int> data2;
22         data2 = data;
23         for (int j = 0; j < m; j++) {
24             cin >> data[j];
25         }
26         int pre = 0;
27         for (int j = 0; j < m; j++) {
28             data2[j] = data[j] - pre;
29             pre = data[j];
30         }
31 
32         int start = 0;
33         int end;
34         int sz = data.size();
35         while (start < sz) {
36             for (int a = start; a < data.size(); a++) {
37                 if (data[a] == (a + 1)) {
38                     end = a + 1;
39                     break;
40                 }
41             }
42             vector<int> stack;
43             for (int b = start; b < end; b++) {
44                 if (0 == data2[b]) {
45                     int szk = stack.size() - 1;
46                     cout << stack[szk] << " ";
47                     stack.resize(szk);
48                 } else {
49                     cout << 1 << " ";
50                     int szk = stack.size();
51                     for (int d = 0; d < szk; d++) {
52                         stack[d] += data2[b];
53                     }
54                     for (int c = 0; c < data2[b] - 1; c++) {
55                         stack.push_back(data2[b] - c);
56                     }
57 
58                 }
59             }
60             start = end;
61         }
62         cout << endl;
63 
64     }
65     return 0;
66 }
原文地址:https://www.cnblogs.com/kakamilan/p/3009248.html