CodeForces 361B Levko and Permutation
生活随笔
收集整理的這篇文章主要介紹了
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
總結
以上是生活随笔為你收集整理的CodeForces 361B Levko and Permutation的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 工厂模式——JavaScript
- 下一篇: 韩顺平循序渐进学java 第12讲 多态