Codeforces 932.C Permutation Cycle
2 seconds
256 megabytes
standard input
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 ≤ N, g(i) equals either A or B.
The only line contains three integers N, A, B (1 ≤ N ≤ 106, 1 ≤ A, B ≤ N).
If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to N.
9 2 5
6 5 8 3 4 1 9 2 7
3 2 1
1 2 3
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的更多相关文章
- 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 1208D]Restore Permutation (树状数组)
[Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C】 Permutation Cycle
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] p[i] = p[p[i]]一直进行下去 在1..n的排列下肯定会回到原位置的. 即最后会形成若干个环. g[i]显然等于那个环的大 ...
- CodeForces 483C Diverse Permutation
Diverse Permutation Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- Codeforces 932 E. Team Work(组合数学)
http://codeforces.com/contest/932/problem/E 题意: 可以看做 有n种小球,每种小球有无限个,先从中选出x种,再在这x种小球中任选k个小球的方案数 选出的 ...
- codeforces 483C.Diverse Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...
- 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 ...
- Codeforces 285C - Building Permutation
285C - Building Permutation 思路:贪心.因为每个数都不同且不超过n,而且长度也为n,所有排列只能为1 2 3 ......n.所以排好序后与对应元素的差值的绝对值加起来就是 ...
- codeforces C. Diverse Permutation
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- IntelliJ IDEA 12详细开发教程(一)思想的转变与新手入门【转】
转载地址:http://bangqu.com/alicas/blog/433 从事软件开发工作以来,提高自己的开发效率,提高自己编码的规范,提高编码深度层次,这三样一直都是自己努力去追求的事情. 最近 ...
- 【转载】C#批量插入数据到Sqlserver中的三种方式
引用:https://m.jb51.net/show/99543 这篇文章主要为大家详细介绍了C#批量插入数据到Sqlserver中的三种方式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本篇, ...
- php-5.6.26源代码 - opcode执行
文件 php-5.6.26/Zend/zend_vm_execute.h ZEND_API void execute_ex(zend_execute_data *execute_data TSRMLS ...
- 提高mysql性能(like搜索替换 )
一 .mysql用find_in_set代替like搜索提高性能 SELECT * from mobantestinfo1 where find_in_set('33',info2); 二 .使用内部 ...
- 对Neural Machine Translation by Jointly Learning to Align and Translate论文的详解
读论文 Neural Machine Translation by Jointly Learning to Align and Translate 这个论文是在NLP中第一个使用attention机制 ...
- windows系统下用VScode配置远程编辑服务器文件的环境!通过Rmate方法
虽然公司电脑win可以通过Xshell通过SSH远程连接家中内网linux服务器了,但是只能用vim编辑文件有点不爽. 于是上网查询,windows下使用vscode远程编辑服务器文件的办法.参照博文 ...
- python——闰年的判断
写一个程序,判断给定年份是否为闰年. 这样定义闰年的:能被4整除但不能被100整除,或者能被400整除都是闰年. while(1): year = input("请输入一个年份,让我判断一下 ...
- python sys模块和序列化模块
sys模块是与python解释器交互的一个接口: sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit(0),错误退出sys.exit( ...
- luoguP1726 上白泽慧音
P1726 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...
- android onCreate的两个方法
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { } override ...