K-skip Permutation (CodeForces - 103117K)

第一周题单

E - K-skip Permutation (CodeForces - 103117K)

For a permutation P = p 1 , p 2 , ⋯ , p n P=p_1,p_2,⋯,p_n P=p1,p2,,pn of n n n, let f ( P , k ) f(P,k) f(P,k) be the number of i i i satisfying 1 ≤ i < n 1≤i<n 1i<n and p i + k = p i + 1 p_i+k=p_{i+1} pi+k=pi+1.
Given two integers n n n and k k k, your task is to find a permutation P P P of n n n such that f ( P , k ) f(P,k) f(P,k) is maximized.
Recall that in a permutation of n n n, each integer from 1 1 1 to n n n (both inclusive) appears exactly once.

Input

There is only one test case in each test file.
The first and only line contains two integers n n n and k ( 1 ≤ n , k ≤ 1 0 6 ) k(1≤n,k≤10^6) k(1n,k106).

Output

Output one line containing n n n integers indicating a permutation P P P of n n n that maximizes f ( P , k ) f(P,k) f(P,k). 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!

Sample1

Input

3 1

Output

1 2 3

Sample2

Input

7 3

Output

2 5 1 4 7 3 6

Sample3

Input

3 7

Output

1 3 2

题目大意

输出数列一个的数列 P = p 1 , p 2 , ⋯ , p n P=p_1,p_2,⋯,p_n P=p1,p2,,pn,数列中的数满足 p i + k = p i + 1 ( 1 ≤ i < n ) p_i+k=p_{i+1}(1≤i<n) pi+k=pi+1(1i<n),数列中每个数的大小都在 1 1 1 n n n之间

题解过程

一开始看不懂题目什么意思,直接从输入输出提示还有样例入手,其实就是从 1 1 1开始,先输出 1 , 1 + k , 1 + 2 k , . . . 1,1+k,1+2k,... 1,1+k,1+2k,...,然后输出 2 , 2 + k , 2 + 2 k , . . . 2,2+k,2+2k,... 2,2+k,2+2k,...,以此类推,直到输出完 1 1 1 n n n的所有数,比如别忘记最后一位数后面不能加空格,所以用一个计数器记一下数

代码部分(cpp)
#include <iostream>
using namespace std;
void solution()
{
    int n, k;
    cin >> n >> k;
    int num = 0;
    for (int i = 1; i <= k; i++)
    {
        for (int j = i; j <= n; j += k)
        {
            num++;
            if (num == n)
                cout << j;
            else
                cout << j << " ";
        }
    }
}
int main(int argc, const char **argv)
{
    solution();
    return 0;
}

刚开始学习,欢迎指正

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值