zoukankan      html  css  js  c++  java
  • Codeforces Round #275 (Div. 2) C

    题目传送门:http://codeforces.com/contest/483/problem/C


    题意分析:题目意思没啥好说的。

    去搞排列列举必须TLE。那么就想到构造。 1。n。2。n-1。3。n-2这个样子。

    k/2就是须要交换的元素对数,还须要考虑一下k的奇偶去推断没交换的元素是顺序输出还是逆序输出。自己尝试下几个数据就明确了。



    代码:

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    
    using namespace std;
    
    
    typedef long long LL;
    
    int p[100005];
    int main()
    {
        int n,k;
        while(cin>>n>>k)
        {
            for(int i=0; i<n; i++)
            {
                p[i]=i+1;
            }
            int flag=0;
            int temp=n-1;
            int m=k/2;
            int x=k;
            while(m--)
            {
                printf("%d ",p[flag]);
                printf("%d ",p[temp]);
                flag++;
                temp--;
            }
            if(x%2==0)
            {
                for(int i=temp; i>=flag; i--)
                {
                    printf("%d ",p[i]);
                }
            }
            if(x%2==1)
            {
                for(int i=flag; i<=temp; i++)
                {
                    printf("%d ",p[i]);
                }
            }
            printf("
    ");
        }
    }
    


  • 相关阅读:
    语言相关
    一道简单DP题
    一道概率题
    Android CrashHandler
    一道简单数学题
    面试中遇到的随机题目
    VMWare 无损扩展磁盘大小
    Android 源码编译记录
    Android handler 内存泄露分析及解决方法
    Android 反编译
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/7246925.html
Copyright © 2011-2022 走看看