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/ ...
随机推荐
- linux入门基础——linux软件管理RPM
由于linux入门基础是基于CentOS解说的,讲的是CentOS上的软件包管理.ubuntu的软件包管理有这些:ubuntu软件包管理,包管理指南,ubuntu软件包管理. linux软件管理:RP ...
- 【教程】怎样申请Chrome应用商店(Web Store)开发人员
首先你须要一张信用卡,假设你没有的话.能够借用父母或他人的(多见于学生党) 假设你有信用卡.你还得看看信用卡正面是否有注明"VISA"."MasterCard" ...
- java纯数字加密解密实例
我们都知道,在用户加入信息时,一些比較敏感的信息,如身份证号,手机号,用户的登录password等信息,是不能直接明文存进数据库的.今天我们就以一个详细的样例来说明一下纯数字的java加密解密技术. ...
- js实现replaceAll功能
js中没有原生的replaceAll 方法. function replaceAll(str , replaceKey , replaceVal){ var reg = new RegExp(repl ...
- delphi的万能数据库操作
好多人都抱怨delphi没有提供一个可以把任意数据放入数据库的控件,虽然说用代码实现也不难,但是有控件会更方便,这次我终于还是抽出空来做了这么个控件,以后就可以直接拖放了.它支持把任意数据类型写入数据 ...
- oracle安装登录sqlplus / as sysdba然后报错ERROR: ORA-01031 insufficient privileges
解决办法: 一般情况下检查操作系统的登录用户是否包含在ORA_DBA组中. 控制面板->管理工具->计算机管理->系统工具->本地用户和组->ORA_DBA组. 如果OR ...
- caioj1275&&hdu4035: 概率期望值6:迷宫
期望的大难题,%%ZZZ大佬的解释,不得不说这是一道好题(然而膜题解都没完全看懂,然后就去烦ZZZ大佬) 简单补充几句吧,tmp的理解是个难点,除以tmp的原因是,当我们化简时,子节点也有一个B*f[ ...
- YTU 2553: 谁是赢家
2553: 谁是赢家 时间限制: 1 Sec 内存限制: 128 MB 提交: 94 解决: 25 题目描述 某一天,hcbbt等一群弱菜去tamara巨巨家里一起玩了一个卡牌游戏.巨 巨家里有2 ...
- YTU 2928: 取不重复的子串。
2928: 取不重复的子串. 时间限制: 1 Sec 内存限制: 128 MB 提交: 5 解决: 5 题目描述 输入字母构成的字符串(不大于30字符)从中读取3个不重复的字符,求所有取法,取出的 ...
- Local Databases with SQLiteOpenHelper
Overview For maximum control over local data, developers can use SQLite directly by leveraging SQLit ...