zoukankan      html  css  js  c++  java
  • Codeforces 482

    这是一道蛮基础的构造题。

               - k         +(k - 1)      -(k - 2) 

    1 + k ,    1 ,         k ,             2,    ...................

               /          /            /

              k          k-1          k-2

    如图所示,先构造第一个数,就是1 + k, 然后接下来每个数字和上个数相差k , k -1 , k -2

    这样下来,最后一个数字就是一个中间的数字,过程就是不断向中间逼近。

    在k + 1后面的数字,只要升序输出就可以了。

    构造题还是不太熟练阿 QAQ

    贴代码了:

    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #define ll long long
    #define Max(a,b) (((a) > (b)) ? (a) : (b))
    #define Min(a,b) (((a) < (b)) ? (a) : (b))
    #define Abs(x) (((x) > 0) ? (x) : (-(x)))
    using namespace std;
    const int INF = 0x3f3f3f3f;
    
    int a[100001];
    
    int main(){
        int i, j, k, t, m, n;
        while(EOF != scanf("%d%d",&n,&k)){
            if(k == 1){
                for(i = 1; i < n; ++i)  printf("%d ",i);
                printf("%d
    ",n);
                continue;
            }
    
            a[1] = 1 + k;
            for(i = 2; i <= k + 1; ++i){
                if(i % 2 == 0)
                    a[i] = a[i - 1] - (k - (i - 2));
                else
                    a[i] = a[i - 1] + (k - (i - 2));
            }
            int cur = 1;
            for(i = k + 2; i <= n; ++i){
                a[i] = k + 1 + cur++;
            }
            for(i = 1; i < n; ++i){
                printf("%d ",a[i]);
            }
            printf("%d
    ",a[n]);
        }
        return 0;
    }
  • 相关阅读:
    本月周六周日LIST集合
    c#动态调用WEBSERVICE接口
    c#调用
    web上传下载文件
    MVC 的知识
    MongoDB 无法创建抽象类的问题,
    并行活动
    C# 字符串计算表达式
    c# 将字符串转换为逻辑表达式(字符串转换布尔)
    C# 中间语言、CLR、CTS、CLS
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4055048.html
Copyright © 2011-2022 走看看