【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

p[i] = p[p[i]]一直进行下去 在1..n的排列下肯定会回到原位置的。
即最后会形成若干个环。
g[i]显然等于那个环的大小。
即让你形成若干个环。
每个环的大小只能为A或B
则相当于问A*x+B*y=n是否有解。
可以枚举x然后看看n-A*x能否被B整除。

构造x个长度为A的环,y个长度为B的环就好了

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 1e6; int aa[N+10],n,a,b; void dfs(int numa,int numb){
int now = 1;
for (int i = 1;i <= numa;i++){
int prenow = now;
for (int j = 1;j <= a;j++){
aa[now] = now+1;
now++;
}
aa[now-1] =prenow;
}
while (numb--){
int prenow = now;
for (int j = 1;j <= b;j++){
aa[now] = now+1;
now++;
}
aa[now-1] = prenow;
}
for (int i = 1;i <= n;i++)
cout<<aa[i]<<' ';
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> a >> b;
for (int i = 0;i <= N;i++){
int temp = a*i;
temp = n-temp;
if (temp<0) break;
if (temp%b==0){
dfs(i,temp/b);
return 0;
}
}
cout<<-1<<endl;
return 0;
}

【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C】 Permutation Cycle的更多相关文章

  1. 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) D】Tree

    [链接] 我是链接,点我呀:) [题意] 让你在树上找一个序列. 这个序列中a[1]=R 然后a[2],a[3]..a[d]它们满足a[2]是a[1]的祖先,a[3]是a[2]的祖先... 且w[a[ ...

  2. 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) B】Recursive Queries

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个记忆化搜索. 接近O(n)的复杂度吧 [代码] #include <bits/stdc++.h> using nam ...

  3. 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A】 Palindromic Supersequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 字符串倒着加到原串右边就好 [代码] #include <bits/stdc++.h> using namespace ...

  4. Codeforces 932 A.Palindromic Supersequence (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))

    占坑,明天写,想把D补出来一起写.2/20/2018 11:17:00 PM ----------------------------------------------------------我是分 ...

  5. ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A

    2018-02-19 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 mega ...

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

    靠这把上了蓝 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 megabyte ...

  7. 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 ...

  8. Codeforces 932 B.Recursive Queries-前缀和 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))

    B. Recursive Queries   time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀

    A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. QT笔记 -- (2) 文件相关操作、中文路径乱码

    1.显示文件对话框,选择一个目录,显示选中目录中的所有图片的代码如下 主要class: QFileDialog QStringList QFileInfoList QDir void open(){ ...

  2. Caffe学习--Blob分析

    Caffe_blob 1.基本数据结构 Blob为模板类,可以理解为四维数组,n * c * h * w的结构,Layer内为blob输入data和diff,Layer间的blob为学习的参数.内部封 ...

  3. swift语言点评一

    一.变量定义 1.常量与变量 Use let to make a constant and var to make a variable. 2.类型与推测 However, you don’t alw ...

  4. Mojo For Chromium Developers

    Overview This document contains the minimum amount of information needed for a developer to start us ...

  5. 企业微信H5支付返回不到自己指定的结果页面

    项目:vue做的H5项目,嵌入到企业微信里 发现的问题:支付完成后的跳转页面 跳转不到自己指定的页面 问题在于:调支付接口时,redirectUrl: document.location.protoc ...

  6. vue实现tab栏切换

    html <ul class="tab"> <li v-for="(item,index) in tabs" @click="tab ...

  7. [arc086e]snuke line

    题意: 有n个区间,询问对于$1\leq i\leq m$的每个i,有多少个区间至少包含一个i的倍数? $1\leq N\leq 3\times 10^5$ $1\leq M\leq 10^5$ 题解 ...

  8. nginx 多级7层代理安装配置

    编译安装 yum install zlib-devel -y wget https://nginx.org/download/nginx-1.15.12.tar.gz tar -zxf nginx-1 ...

  9. Oralce中的package和package body

    1.Oracle Package的作用: 可以简化应用设计.提高应用性能.实现信息隐藏.子程序重载 2.ORACLE中的function   .package.package   bodies.pro ...

  10. pandas 3 设置值

    from __future__ import print_function import pandas as pd import numpy as np np.random.seed(1) dates ...