# Codeforces Round #463 C.Permutation Cycle

2018-02-27 10:54:16来源:https://www.jianshu.com/p/c14d90b9db75作者:翡翠森林Z人点击

http://codeforces.com/contest/932/problem/C

（一）何谓Permutation Cycle

（二）例子分析

p[1] = 6, p[2] = 5, p[3] = 8, p[4] = 3, p[5] = 4, p[6] = 1, p[7] = 9, p[8] = 2, p[9] = 7
f(1, j) = f(6, j-1) = p[6] = 1，此时j - 1 = 1 ==> j = 2 ==> g(1) = 2
f(2, j) = f(5, j-1) = f(4, j-2) = f(3, j-3) = f(8, j-4) = p[8] = 2，此时j - 4 = 1 ==> j = 5 ==> g(2) = 5
f(3, j) = f(8, j-1) = f(2, j-2) = f(5, j-3) = f(4, j-4) = p[4] = 3，此时j - 4 = 1 ==> j = 5 ==> g(3) = 5
……

p[1] = 1, p[2] = 2, p[3] = 3
f(1, j) = p[1] = 1 ==> j = 1 ==> g(1) = 1
f(2, j) = p[2] = 2 ==> j = 1 ==> g(2) = 1
f(3, j) = p[3] = 3 ==> j = 1 ==> g(3) = 1

（三）思路

3x + 6y = 9 ==> x = 1, y = 1

4x + 6y = 9，无解。

``#include<cstdio>int main(){    int n, a, b;    int cnta, cntb;    int flag = false;    scanf("%d %d %d", &n, &a, &b);    for (int i = 0; i * a <= n; i++)    {        int t = n - a * i;        if (t % b == 0)        {            cnta = i;            cntb = t / b;            flag = true;            break;        }    }    int num = 1;    int lastNum = num;    if(!flag)    {         printf("-1/n");    }    else    {        for(int i = 1;i <= cnta;i++)        {            for(int k = 1;k < a;k++)            {                printf("%d ",++num);            }            printf("%d ",lastNum);            num++;            lastNum = num;        }        for(int i = 1;i <= cntb;i++)        {            for(int k = 1;k < b;k++)            {                printf("%d ",++num);            }            printf("%d ",lastNum);            num++;            lastNum = num;        }    }    return 0;}``

``9 2 52 1 4 3 6 7 8 9 5``

feicuisenlin_12x12.jpg