CodeForces 361B Levko and Permutation
题意:有n个数,这些数的范围是[1,n],并且每个数都是不相同的。你需要构造一个排列,使得这个排列上的数与它所在位置的序号的最大公约数满足 > 1,并且这些数的个数恰好满足k个,输出这样的一个排列。
思路:只需要后k个数与下标一样,前n-k个数逆序输出就复合题意。
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<iostream>
- #include<cstdlib>
- #include<string>
- #include<cmath>
- #include<vector>
- using namespace std;
- const int maxn=1e5+;
- const double eps=1e-;
- const double pi=acos(-);
- #define ll long long
- #define clc(a,b) memset(a,b,sizeof(a))
- int main()
- {
- int n,m;
- scanf("%d%d",&n,&m);
- if(n==m)
- {
- printf("-1\n");
- }
- else
- {
- printf("%d ",n-m);
- for(int i=;i<n-m;i++)
- printf("%d ",i);
- for(int i=n-m+;i<=n;i++)
- printf("%d ",i);
- }
- return ;
- }
CodeForces 361B Levko and Permutation的更多相关文章
- codeforces B. Levko and Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这 ...
- Codeforces 691D Swaps in Permutation
Time Limit:5000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Prac ...
- Codeforces 500B. New Year Permutation[连通性]
B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- 【搜索】【并查集】Codeforces 691D Swaps in Permutation
题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...
- cf B. Levko and Permutation
http://codeforces.com/contest/361/problem/B #include <cstdio> #include <cstring> #includ ...
- [Codeforces 864D]Make a Permutation!
Description Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to ...
- Codeforces 785E. Anton and Permutation
题目链接:http://codeforces.com/problemset/problem/785/E 其实可以CDQ分治... 我们只要用一个数据结构支持单点修改,区间查询比一个数大(小)的数字有多 ...
- Codeforces 804E The same permutation(构造)
[题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出 ...
随机推荐
- 利用数据库链做DML操作时报ORA-02069: global_names parameter must be set to TRUE for this operation
按照 http://space.itpub.net/195110/viewspace-711110 的说法顺利解决问题. 通过DBLink更新远程数据的时候,如果使用到本地的sequence.函数.过 ...
- [C和指针] rearrange.c
C和指针_程序1.1_重排字符 /* ** 这个程序从标准输入(键盘)中读取输入行并按需求处理后在标准输出(屏幕)中打印, ** 每个输入行的后面一行是该行按需求处理后的输出内容. ** ** 输入的 ...
- C# - implicit, explicit
如果类型直接没有继承关系,也没有共享接口,想在这两个类型之间进行转换,就必须重载转换运算符. 此时需要关键字implicit和explicit. 下面定义了类型ConvClass1和ConvClass ...
- Python中异常(Exception)的总结
Python中的异常处理 异常处理的语句结构 try: <statements> #运行try语句块,并试图捕获异常 except <name1>: <statement ...
- linux nginx安装
操作系统centOS7安装nginx: 1.如果centOS7中未安装编译器,先安装gcc编译模块 yum install gcc gcc-c++ ncurses-devel perl 2.安装ngi ...
- DIY RazorEngine 的程序集生成方式
最近遇到一个项目,要使用RazorEngine做模板引擎,然后完成简易的CMS功能,以减轻重复的CDRU操作,同时复用管理后台.没错,使用的正是GIT HUB上的开源项目:https://github ...
- BZOJ 3953 Self-Assembly 解题报告
首先,我们可以先考虑一个暴力一点的算法: 对于任意两个分子,如果它们能以至少一种进行匹配,那么我们就在这两个分子之间连一条边. 然后如果我们能找到一个环,就说明是 unbounded,否则就是 bou ...
- 关于table的一些兼容性问题
不多说,先来看两个常用的简单效果 ---- 兼容拼比一(普通边线效果) 图一:谷歌.火狐.ie8+下 图二:ie6/7下 从图中看出,ie6/7其实是不认识tr边框线的,,所以平时做项目时候,我们一般 ...
- java.utils.HashMap数据结构分析(转)
上图为Hashmap的数据结构图,具体实线是采用数组结合链表实现,链表是为了解决在hash过程中因hash值一样导致的碰撞问题. 所以在使用自定义对象做key的时候,一定要去实现hashcode方 ...
- Ember.js demo5
<!DOCTYPE html> <html> <head> <meta name="description" content=" ...