Article From:https://www.cnblogs.com/evenbao/p/9740235.html

[Title link]

        https://codeforces.com/contest/482/problem/A

[Algorithm]

         First, a sequence of (K + 1) numbers is constructed to satisfy their difference 1-k.

         For I > K + 1, Ai = I

         Time complexity: O (N)

[Code]

        

#include<bits/stdc++.h>
using namespace std;

template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}
int main()
{
        
        int n , k;
        read(n); read(k);
        printf("1");
        int value = k , now = 1;
        for (int i = 1; i <= k; i++) 
        {
                if (i & 1) now += value;
                else now -= value;
                printf(" %d",now);
                value--;        
        }
        for (int i = k + 2; i <= n; i++) printf(" %d",i);
        printf("\n");
        
        return 0;
    
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *