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 ...
随机推荐
- JQuery实现父级选择器(广告实现)
效果图如下: HTML代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- tcp文件下载客户端+服务端
客户端: import socket if __name__ == '__main__': # 创建tcp客户端socket tcp_client_socket = socket.socket(soc ...
- MySQL的where条件优化
where 条件优化 适合select delete update 1.避免无用的括号 ((a AND b) AND c OR (((a AND b) AND (c AND d)))) -> ...
- php 操作 mysql 实现批量执行mysql语句 mysql文件
<?php /** * 批量运行sql文件 * 正则分隔是重点 preg_split("/;[\r\n]+/", filecontent) */ $config = requ ...
- Uncaught Error: Script error for "popper.js", needed by: bootstrap - require.js
Uncaught Error: Script error for "popper.js", needed by: bootstrap https://requirejs.org/d ...
- 访问远程mysql数据库,出现报错,显示“1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server“
在使用Navicat for MySQl访问远程mysql数据库,出现报错,显示“1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to t ...
- JZOJ 3534. 【NOIP2013提高组day1】货车运输
Description A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物,司机们想知道每辆车在不超过车辆限重的 ...
- B1016 部分A+B (15分)
B1016 部分A+B (15分) 输入格式: 输入在一行中依次给出 A.DA.B.DB,中间以空格分隔,其中 \(0<A,B<10^10\). 输出格式: 在一行中输出 PA+PB的值. ...
- [Bzoj2282]消防(二分答案+树的直径)
Description 某个国家有n个城市,这n个城市中任意两个都连通且有唯一一条路径,每条连通两个城市的道路的长度为zi(zi<=1000). 这个国家的人对火焰有超越宇宙的热情,所以这个国家 ...
- MySQL忘记密码怎么重置
1打开mysql.exe和mysqld.exe所在的文件夹,复制路径地址 输入命令 mysqld --skip-grant-tables 回车,此时就跳过了mysql的用户验证.注意输入此命令之后 ...