We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0d22d95 commit 2f59004Copy full SHA for 2f59004
codeforces/constructive_algorithms/1650D.md
@@ -0,0 +1,29 @@
1
+# codeforces 1650D
2
+
3
+> 这是一类题目,当我们想得到一个序列的时候,就通过最后一个位置的信息进行回溯。相同的做法还有迪杰斯特拉算法最短路径输出
4
5
+```cpp
6
+#include <bit/stdc++.h>
7
+using namespace std;
8
+int a[10010], b[10010];
9
+int main(){
10
+ ios_base::sync_with_stdio(0);
11
+ cin.tie(0);
12
+ int t, n;
13
+ cin >> t;
14
+ while(t--){
15
+ cin >> n;
16
+ for(int i = 0; i < n; i++) cin >> a[i];
17
+ for(int i = n - 1; i >= 0; i--) { //从后往前回溯
18
+ int j = find(a, a + n, i + 1) - a;
19
+ b[i] = (j + 1) % (i + 1);
20
+ rotate(a, a[j], a + i + 1);
21
+ }
22
+ for(int i = 0; i < n; i++) cout << b[i] << ' ';
23
+ cout << endl;
24
25
+ return 0;
26
+}
27
+```
28
29
0 commit comments