题目传送门: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("\n");
}
}

最新文章

  1. 导入一些常用命令比如(rz),关闭防火墙外面可以访问
  2. [转]CSS 表单元素对齐详解
  3. js生成二维码实例(真实有效)
  4. BZOJ 1002 [ FJOI 2007 ]
  5. MSChart参考
  6. PCA和Softmax分类比较—Mnist与人脸数据集
  7. git(osx)上的一个git commit无法正确提交的问题
  8. 1201: [HNOI2005]数三角形 - BZOJ
  9. 不规则三角网(TIN)(转)
  10. selenium文件上传的实现
  11. Android设置背景
  12. 由Spring框架中的单例模式想到的
  13. spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist
  14. hibernate 动态多数据库
  15. Storm入门-Storm与Spark对比
  16. [转][C#]服务安装卸载命令
  17. day3 python学习
  18. shell-保留文件系统下剩余指定数目的文件
  19. python基础训练题1-列表操作
  20. FormsAuthentication 使用指南

热门文章

  1. bootstrap只有遮罩层没有对话框的解决方法
  2. Group Shifted Strings -- LeetCode
  3. [COCI2015]FUNGHI
  4. Filter过滤器笔记1
  5. CAP理论下对比ACID模型与BASE模型
  6. 所有iOS设备的屏幕分辨率
  7. 【转载】uboot的工具mkimage使用方法
  8. VisualStudio Shell简介 — 界面定制
  9. 【译】PHP之道(PHP the right way)
  10. Java 并发工具包 java.util.concurrent 用户指南(转)