列表

详情


NC222763. K-skipPermutation

描述

For a permutation of , let be the number of satisfying and .
Given two integers and , your task is to find a permutation of such that is maximized.
Recall that in a permutation of , each integer from to (both inclusive) appears exactly once.

输入描述

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++(g++ 7.5.0) 解法, 执行用时: 146ms, 内存消耗: 7168K, 提交时间: 2023-04-20 14:33:14

#include<iostream>
using namespace std;
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=k;i++){
		for(int j=i;j<=n;j+=k){
			cout<<j<<" ";
		}
	}
	return 0;
}

C++ 解法, 执行用时: 71ms, 内存消耗: 7124K, 提交时间: 2021-06-14 15:32:38

#include<iostream>
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 解法, 执行用时: 904ms, 内存消耗: 122504K, 提交时间: 2023-04-20 14:55:26

n,k=map(int,input().split())
a=[]
for i in range(1,k+1):
    while i<=n:
        a.append(i)
        i+=k
print(' '.join(map(str,a)))

pypy3 解法, 执行用时: 481ms, 内存消耗: 191856K, 提交时间: 2023-04-17 15:05:53

n,k=map(int,input().split())
a=[]
for i in range(1,k+1):
    while i<=n:
        a.append(i)
        i+=k
print(" ".join(map(str,a)))

上一题