CodeForces 361B Levko and Permutation

题意:有n个数,这些数的范围是[1,n],并且每个数都是不相同的。你需要构造一个排列,使得这个排列上的数与它所在位置的序号的最大公约数满足 > 1,并且这些数的个数恰好满足k个,输出这样的一个排列。

思路:只需要后k个数与下标一样,前n-k个数逆序输出就复合题意。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #include<cstdlib>
 6 #include<string>
 7 #include<cmath>
 8 #include<vector>
 9 using namespace std;
10 const int maxn=1e5+7;
11 const double eps=1e-8;
12 const double pi=acos(-1);
13 #define ll long long
14 #define clc(a,b) memset(a,b,sizeof(a))
15 
16 int main()
17 {
18     int n,m;
19     scanf("%d%d",&n,&m);
20     if(n==m)
21     {
22         printf("-1\n");
23     }
24     else
25     {
26         printf("%d ",n-m);
27         for(int i=1;i<n-m;i++)
28             printf("%d ",i);
29         for(int i=n-m+1;i<=n;i++)
30             printf("%d ",i);
31     }
32     return 0;
33 }
View Code

 

转载于:https://www.cnblogs.com/ITUPC/p/5243808.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值