【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C】 Permutation Cycle
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
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的更多相关文章
- 【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[ ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) B】Recursive Queries
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个记忆化搜索. 接近O(n)的复杂度吧 [代码] #include <bits/stdc++.h> using nam ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A】 Palindromic Supersequence
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 字符串倒着加到原串右边就好 [代码] #include <bits/stdc++.h> using namespace ...
- 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 ----------------------------------------------------------我是分 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Analysis of the Facebook.app for iOS
Analysis of the Facebook.app for iOS Posted Oct 18, 2016 Did you ever wonder why the Facebook.app fo ...
- Xshell调整终端显示的最大行数(缓冲区)
1 选择会话,按顺序点击文件->属性 ,打开"会话属性"窗口 如下 在"会话属性"窗口中选择“终端” 修改缓冲区大小的值:其范围为0~2147483647 ...
- Linux 清空缓存
sync echo 1 > /proc/sys/vm/drop_caches echo 2 > /proc/sys/vm/drop_caches echo 3 > /proc/sys ...
- HDU 5234 Happy birthday【DP】
题意:给出n*m的格子,每个格子的值为w[i][j],在值不超过k的时候,可以往右或者往下走,问从(1,1)走到(n,m)能够得到的最大的值 类似于背包 d[i][j][k]=maxx(d[i-1][ ...
- 多任务-进程之PID
1.进程pid,如何在程序中获取我们的进程号,从而查看当前的进程 # -*- coding:utf-8 -*- from multiprocessing import Process import o ...
- 15条JavaScript最佳实践【转】
本文档整理大部分公认的.或者少有争议的JavaScript良好书写规范(Best Practice).一些显而易见的常识就不再论述(比如要用对象支持识别判断,而不是浏览器识别判断:比如不要嵌套太深). ...
- BZOJ 4472 [Jsoi2015]salesman(树形DP)
4472: [Jsoi2015]salesman Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 417 Solved: 192[Submit][St ...
- C语言传参的类型匹配
有一个这样的问题: 形参const char *p和实参char *c可以匹配 形参const char**p和实参char**c不可以匹配 注:argument和parameter:严格而言,par ...
- django 之数据库模块
前提ajango的 数据库主要是为了存取网站的一些内容,数据库的设置一般放在model.py 下 目录下 我们设置如下的数据库:具体的代码如下面所示: # -*- coding: utf-8 -* ...
- 栈(stack)--c实现(使用双链表)
是不是直接贴代码不太好,我竟然不知道说什么. 写这个考虑的问题,或者是纠结的问题是这个头指针怎么处理,也就是栈的顶部,最后采用的是初始化第一个栈空间浪费掉,栈顶是有元素的.好像应该去学习下画图,没图不 ...