CF932C Permutation Cycle
思路:
构造。
实现:
#include <bits/stdc++.h>
using namespace std;
int res[];
int main()
{
int n, a, b;
while (cin >> n >> a >> b)
{
int maxn = max(a, b), minn = min(a, b);
bool flg = false;
int i = ;
for (; i <= n; i += maxn)
{
if ((n - i) % minn == ) { flg = true; break; }
}
if (!flg) { cout << - << endl; continue; }
int x = i / maxn, y = (n - i) / minn;
int cnt = , last = ;
for (int i = ; i < x; i++)
{
int start = cnt;
for (int j = + i * maxn; j <= maxn + i * maxn; j++)
{
res[cnt++] = j;
}
int tmp = res[start];
int j = start;
for (; j < cnt - ; j++)
{
res[j] = res[j + ];
}
res[j] = tmp;
}
int fuck = cnt;
for (int i = ; i < y; i++)
{
int start = cnt;
for (int j = fuck + + i * minn; j <= fuck + minn + i * minn; j++)
{
res[cnt++] = j;
}
int tmp = res[start];
int j = start;
for (; j < cnt - ; j++)
{
res[j] = res[j + ];
}
res[j] = tmp;
}
for (int i = ; i < cnt; i++) cout << res[i] << " ";
cout << endl;
}
return ;
}
CF932C Permutation Cycle的更多相关文章
- Codeforces 932.C Permutation Cycle
C. Permutation Cycle time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- 【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 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 Round #463
A - Palindromic Supersequence /* 题目大意:给出一个串,构造一个包含该串的回文串 */ #include <cstdio> #include <alg ...
- 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 ...
- 置换及Pólya定理
听大佬们说了这么久Pólya定理,终于有时间把这个定理学习一下了. 置换(permutation)简单来说就是一个(全)排列,比如 \(1,2,3,4\) 的一个置换为 \(3,1,2,4\).一般地 ...
- (转)排列算法 Permutation Generation
转自:http://www.cnblogs.com/dragonpig/archive/2010/01/21/1653680.html http://www.notesandreviews.com/p ...
- Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造
B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
随机推荐
- 《modern operating system》 chapter 6 DEADLOCKS 笔记
DEADLOCKS Both processes are blocked and will remain so forever. This situation is called a deadlock ...
- phpqrcode生成带logo的二维码图片及带文字的二维码图片
<?php require_once "./phpqrcode/phpqrcode.php"; /** * 这样就可以生成二维码了,实际上在png这个方法里还有几个参数需要使 ...
- 【iOS系列】-iOS的多线程解析
[iOS系列]-iOS的多线程解析 iOS的多线程实现技术: 1:GCD -- Grand Central Dispatch 是基于C语言的底层API 用Block定义任务,使用起来非常灵活便捷 提供 ...
- oracle 10g的备份和还原
采用 expdp备份,impdp还原. 注意这二者不等同于exp和imp.oracle 10g以前,可以采用exp.imp,10g及以后,expdp + impdp矣.据说10g里面,如果采用exp, ...
- MYSQL之数据库初窥
mysql数据库 1.数据库简单介绍 数据库概念:是依照数据结构来组织.存储和管理数据的仓库. 2.经常使用术语 数据库:是一些关联表的集合 数据表:表是数据的矩阵,在数据库中看起来 ...
- Lightoj 1018 - Brush (IV)
1018 - Brush (IV) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...
- CodeForces-451E:Devu and Flowers (母函数+组合数+Lucas定理)
Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contain ...
- 聊聊Shiro
Shiro是项目中用的比较多Java安全框架,能满足大多数项目的安全认证.授权流程.相比SpringSecurity的复杂重量级,它更简单易用. Shiro中最关键的两个概念是认证和授权,前者解决确认 ...
- 小程序-demo:小程序示例-page/component2
ylbtech-小程序-demo:小程序示例-page/component2 以下将展示小程序官方组件能力,组件样式仅供参考,开发者可根据自身需求自定义组件样式,具体属性参数详见小程序开发文档. 1. ...
- 去除inline-block的间隙
产生间隙的原因就是标签之间的空格,去除的方法: 1 设置父元素的font-size:0;空格字符的宽高都为0, <div class="demo1 demo2"> &l ...