C. Permutation Cycle
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

For a permutation P[1... N] of integers from 1 to N, function f is defined as follows:

Let g(i) be the minimum positive integer j such that f(i, j) = i. We can show such j always exists.

For given N, A, B, find a permutation P of integers from 1 to N such that for 1 ≤ i ≤ Ng(i) equals either A or B.

Input

The only line contains three integers N, A, B (1 ≤ N ≤ 106, 1 ≤ A, B ≤ N).

Output

If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to N.

Examples
input
9 2 5
output
6 5 8 3 4 1 9 2 7
input
3 2 1
output
1 2 3 
Note

In the first example, g(1) = g(6) = g(7) = g(9) = 2 and g(2) = g(3) = g(4) = g(5) = g(8) = 5

In the second example, g(1) = g(2) = g(3) = 1

题目大意:p是一个置换,要求将一个序列分成若干个环,大小为a或b.(不是很好说......),给出p.

分析:枚举一下a的系数,可以推测出b的系数,如果ax + by = n没有非负整数解,那么就输出-1,否则一个一个环直接构造就好了.

#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio> int n,a,b;
int cnta,cntb;
int flasttg=false;
int main()
{
scanf("%d%d%d",&n,&a,&b);
for (int i = ; i * a <= n; i++)
{
int t = n - a * i;
if (t % b == )
{
cnta = i;
cntb = t / b;
flasttg = true;
break;
}
}
int pos=;
int lastt=pos;
if(!flasttg)
printf("-1\n");
else
{
for(int i = ;i <= cnta;i++)
{
for(int k = ;k < a;k++)
printf("%d ",++pos);
printf("%d ",lastt);
pos++;
lastt=pos;
}
for(int i = ;i <= cntb;i++)
{
for(int k = ;k < b;k++)
printf("%d ",++pos);
printf("%d ",lastt);
pos++;
lastt=pos;
}
}
return ;
}

Codeforces 932.C Permutation Cycle的更多相关文章

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

    C. Permutation Cycle   time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. [Codeforces 1208D]Restore Permutation (树状数组)

    [Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...

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

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] p[i] = p[p[i]]一直进行下去 在1..n的排列下肯定会回到原位置的. 即最后会形成若干个环. g[i]显然等于那个环的大 ...

  4. CodeForces 483C Diverse Permutation

    Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  5. Codeforces 932 E. Team Work(组合数学)

    http://codeforces.com/contest/932/problem/E 题意:   可以看做 有n种小球,每种小球有无限个,先从中选出x种,再在这x种小球中任选k个小球的方案数 选出的 ...

  6. codeforces 483C.Diverse Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...

  7. C. Permutation Cycle

    For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: Let g(i) be t ...

  8. Codeforces 285C - Building Permutation

    285C - Building Permutation 思路:贪心.因为每个数都不同且不超过n,而且长度也为n,所有排列只能为1 2 3 ......n.所以排好序后与对应元素的差值的绝对值加起来就是 ...

  9. codeforces C. Diverse Permutation

    C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. 页面刷新 方法总结 JSP刷新

    1) <meta http-equiv="refresh"content="10;url=跳转的页面"> 10表示间隔10秒刷新一次 2) < ...

  2. python的运行过程剖析·编程语言分类

    总结: 编程语言的分类 编译型: 说明:与汇编语言类似,都有一个编译程序将源代码编译成硬件可执行的二进制代码 特点:执行速度快.同等情况下对系统要求低,适合于开发大型应用程序.数据库系统.操作系统等 ...

  3. python入门基本知识

    1. 什么是语言 语言是一个事物与另外一个事物沟通的介质. python则是人(程序员)与计算机沟通的介质. 2. 什么是编程 编程就是程序员将自己想要让计算机做的事情用编程语言翻译出来写到一系列的文 ...

  4. Makefile (3) 基本语法和使用

    make是用来管理一个工程项目的工具 . Makefile就是这个项目文件 . 1.Makefile 是由若干条规则组成的,每个规则的语法如下所示 : #规则 targets: prerequisit ...

  5. C++基础 对象的管理——单个对象的管理

    1. 为什么要有构造函数和析构函数 面向对象的思想是从生活中来,手机.车出厂时,是一样的. 这些对象都是被初始化后才上市的,初始化是对象普遍存在的一个状态. 普通方案: 对每个类提供一个 init 函 ...

  6. perl连接mysql数据库

    首先需要安装 ppm install DBD::mysql use strict; use DBI; my $host = "localhost"; # 主机地址 my $driv ...

  7. 变量存储类型(auto static extern)

    auto 动态存储类型变量(函数内部变量存储默认为 auto型) auto只用于函数内部定义,单片机在执行这个函数时为它分配内存地址,当函数执行完毕返回后,auto变量会被销毁,再次进入这个函数时,它 ...

  8. Hihocoder 1275 扫地机器人 计算几何

    题意: 有一个房间的形状是多边形,而且每条边都平行于坐标轴,按顺时针给出多边形的顶点坐标 还有一个正方形的扫地机器人,机器人只可以上下左右移动,不可以旋转 问机器人移动的区域能不能覆盖整个房间 分析: ...

  9. Eclipse 创建 XML 文件---Eclipse教程第12课

    打开新建 XML 文件向导 你可以使用新建 XML 文件向导来创建 XML 文件.打开向导的方式有: 点击 File 菜单并选择 New > Other 点击新建下拉框 () 选择 Other ...

  10. SuperHelper——灵活通用的、开源的.Net ORM微型框架

    SuperHelper是博主利用业余时间编写的一个ORM微型框架,除了可以提高开发效率,与其它ORM框架相比,博主更加喜欢SuperHelper的使用简单.适用范围广的特点. 简介 SuperHelp ...