CF932C Permutation Cycle

Posted 王宜鸣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF932C Permutation Cycle相关的知识,希望对你有一定的参考价值。

思路:

构造。

实现:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int res[1000005];
 4 int main()
 5 {
 6     int n, a, b;
 7     while (cin >> n >> a >> b)
 8     {
 9         int maxn = max(a, b), minn = min(a, b);
10         bool flg = false;
11         int i = 0;
12         for (; i <= n; i += maxn)
13         {
14             if ((n - i) % minn == 0) { flg = true; break; }
15         }
16         if (!flg) { cout << -1 << endl; continue; }
17         int x = i / maxn, y = (n - i) / minn;
18         int cnt = 0, last = 0;
19         for (int i = 0; i < x; i++)
20         {
21             int start = cnt;
22             for (int j = 1 + i * maxn; j <= maxn + i * maxn; j++)
23             {
24                 res[cnt++] = j;
25             }
26             int tmp = res[start];
27             int j = start;
28             for (; j < cnt - 1; j++)
29             {
30                 res[j] = res[j + 1];
31             }
32             res[j] = tmp;
33         }
34         int fuck = cnt;
35         for (int i = 0; i < y; i++)
36         {
37             int start = cnt;
38             for (int j = fuck + 1 + i * minn; j <= fuck + minn + i * minn; j++)
39             {
40                 res[cnt++] = j;    
41             }
42             int tmp = res[start];
43             int j = start;
44             for (; j < cnt - 1; j++)
45             {
46                 res[j] = res[j + 1];
47             }
48             res[j] = tmp;
49         }
50         for (int i = 0; i < cnt; i++) cout << res[i] << " ";
51         cout << endl;
52     } 
53     return 0;
54 }

 

以上是关于CF932C Permutation Cycle的主要内容,如果未能解决你的问题,请参考以下文章

ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C Permutation Cycle

Square Root of Permutation - CF612E

[CF117C]Cycle

CF359B Permutation (构造)

CF1295E Permutation Separation

## CF1352G Special Permutation