【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 ...
随机推荐
- 004.JMS消息结构
JMS的消息结构类似于HTTP请求的结构分为三部分: 消息头 消息属性 消息体 下面分别说明三部分的内容标准. 1. 消息头 消息头包含消息的识别信息和路由信息,其标准属性如下: 下面介绍的参数都可以 ...
- hdu 6082 - 完全背包,打表。
2017-08-06 15:02:50 Accepted 1003 187 MS 2168 K G++ redips 对背包有了进一步的认识 ----------------------------- ...
- K8s初探
1. K8s概述 2. K8s的工作原理 什么是K8s 用法: 核心概念 集群 Kubernetes Master Node Pod Lable Replication Con ...
- [六省联考2017]分手是祝愿(期望+DP)
题解 很容易想出来最优策略是什么. 就是从n到1看到开着的灯就把它关了 我们预处理出当前状态把灯全部关闭后的最少步数cnt 然后我们的主人公就要瞎按... 设dp[i]代表当前状态最优解为i步时走到d ...
- Laravel关联模型中过滤结果为空的结果集(has和with区别)
首先看代码: $userCoupons = UserCoupons::with(['coupon' => function($query) use($groupId){ return $quer ...
- 【codeforces 816C】Karen and Game
[题目链接]:http://codeforces.com/contest/816/problem/C [题意] 给你一个n*m的矩阵; 一开始所有数字都是0; 每次操作,你能把某一行,或某一列的数字全 ...
- MYSQL锁表问题的解决方法
本文实例讲述了MYSQL锁表问题的解决方法.分享给大家供大家参考,具体如下: 很多时候!一不小心就锁表!这里讲解决锁表终极方法! 案例一 mysql>show processlist; 参看sq ...
- 成都磨子桥技工学校 / 2016届练习区 0003:jubeeeeeat
0003:jubeeeeeat 总时间限制: 1000ms 内存限制: 256000kB 描述 众所周知,LZF很喜欢打一个叫Jubeat的游戏.这是个音乐游戏,游戏界面是4×4的方阵,会根据音乐 ...
- Qt之QFileIconProvider
简述 QFileIconProvider类为QDirModel和QFileSystemModel类提供了文件图标. 简述 共有类型 公共函数 示例 IconType 效果 源码 QFileInfo 效 ...
- HDU 1026 Ignatius and the Princess I(BFS+记录路径)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...