思路:
构造。
实现:
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 }