NC236062. K-skip Permutation
描述
输入描述
There is only one test case in each test file.The first and only line contains two integers and ().
输出描述
Output one line containing integers indicating a permutation of that maximizes . If there are multiple valid answers you can output any of them.Please, DO NOT output extra spaces at the end of the line, or your answer may be considered incorrect!
示例1
输入:
3 1
输出:
1 2 3
示例2
输入:
7 3
输出:
2 5 1 4 7 3 6
示例3
输入:
3 7
输出:
1 3 2
C++ 解法, 执行用时: 110ms, 内存消耗: 7140K, 提交时间: 2022-04-03 09:40:03
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; cin>>n>>k; for(int i=1;i<=k;i++){ for(int j=i;j<=n;j+=k){ cout<<j<<' '; } } }
Python3 解法, 执行用时: 1310ms, 内存消耗: 96372K, 提交时间: 2023-05-11 21:39:09
n,k=map(int,input().split()) x=[] for i in range(1,k+1): for j in range(i,n+1,k): x.append(str(j)) print(" ".join(x))