思路:

构造。

实现:

 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 }

转载于:https://www.cnblogs.com/wangyiming/p/8463628.html

CF932C Permutation Cycle相关推荐

  1. Codeforces 题目合集+分类+代码 【Updating...】【361 in total】

    961A - Tetris                                                模拟                                      ...

  2. 近世代数--置换群--置换permutation分解成什么?置换的级如何计算?

    近世代数--置换群--置换permutation分解成什么?置换的级如何计算? 置换的分解 置换的级计算 博主是初学近世代数(群环域),本意是想整理一些较难理解的定理.算法,加深记忆也方便日后查找:如 ...

  3. 遗传算法:最全的序列整数编码交叉算子 permutation encoding integer encoding crossover operator

    关于遗传算法中的permutation coding问题的交叉算子种类介绍 见文章 Permutation integer encoding 序列编码是整数编码的一种,可以用于解决TSP(旅行商问题) ...

  4. Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...

  5. 【C++】C++11 STL算法(七):排列操作(Permutation operations)、数值操作(Numeric operations)

    排列操作(Permutation operations) 一.is_permutation 1.原型: template< class ForwardIt1, class ForwardIt2 ...

  6. LeetCode 76. Minimum Window Substring / 567. Permutation in String

    76. Minimum Window Substring 典型Sliding Window的问题,维护一个区间,当区间满足要求则进行比较选择较小的字串,重新修改start位置. 思路虽然不难,但是如何 ...

  7. 【LeetCode】142 - Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...

  8. 解决load cycle count的一个偏方,告别硬盘卡卡响

    load cycle count猛增,笔记本电脑硬盘喀嚓喀嚓响,我倒不担心硬盘寿命,但是实在烦人那声音,系统也时常被卡一下.我曾使用了hdparm -B 254 /dev/sda 的方法,但是硬盘升温 ...

  9. rewrite or internal redirection cycle while processing nginx重定向报错

    2018/05/07 15:03:42 [error] 762#0: *3 rewrite or internal redirection cycle while processing "/ ...

最新文章

  1. 深度高能粒子对撞追踪:Kaggle TrackML粒子追踪挑战赛亚军访谈
  2. RegeX —— 可视化正则表达式替换器
  3. 基于傅里叶算子的手势识别
  4. Spring BeanFactory 容器
  5. 将自定义功能添加到Spring数据存储库
  6. [读书笔记][golang]《go语言-云动力》
  7. 百度宣布搜索公司战略转型:原总裁向海龙离职 沈抖晋升为高级副总裁
  8. js关闭当前页面窗口的问题
  9. Bsie(鄙视IE)
  10. 基于 HTML5 的 3D 工业互联网展示方案
  11. 西威变频器avo下载调试资料_图解变频器的应用与接线,电气工程师必备
  12. jason表情包在线生成源码
  13. 权限设计-系统登录用户权限设计
  14. c语言鼠标滚动条,xtraScrollableControl 滚动条随鼠标滚动
  15. kk5.0服务器信息怎么填,蓝凌KK5.0:企业大连接的IT落地支撑平台
  16. IT安全面试问题汇总
  17. 2019东北四省 H. Skyscraper (树状数组)
  18. PPT制作图片磨砂玻璃艺术效果
  19. 随机变量的函数的分布
  20. (重温)JavaWeb--Cookie 和 Session入门总结(了解cookie和session这一篇就够了)

热门文章

  1. Vue中遍历不规律的json对象(递归)
  2. InnoDB存储结构这一篇就够了
  3. java数组赋值_JAVA 给数组赋值
  4. 杰理之关掉混响的效果【篇】
  5. ZYNQ 高速接口系列(一) PCIe接口
  6. 基于RISC-V CH32V103的鼠标键盘摇杆手柄Joystick学习开发板--实例Eg3_KeyBoard
  7. DNS服务概念,术语,角色介绍
  8. 7/8~馈线接头的制作
  9. 【安全牛学习笔记】CSRF跨站请求伪造***漏洞的原理及解决办法
  10. python 类与对象练习题