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

Codeforces Round #275 (Div. 2) C的更多相关文章

  1. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  2. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  3. 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

    题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...

  4. [Codeforces Round #275 (Div. 2)]B - Friends and Presents

    最近一直在做 codeforces ,总觉得已经刷不动 BZOJ 了? ——真是弱喵 你看连 Div.2 的 B 题都要谢谢题解,不是闲就是傻 显然我没那么闲 ╮(╯_╰)╭ 我觉得这题的想法挺妙的~ ...

  5. Codeforces Round #275(Div. 2)-C. Diverse Permutation

    http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...

  6. Codeforces Round #275 (Div. 2)-A. Counterexample

    http://codeforces.com/contest/483/problem/A A. Counterexample time limit per test 1 second memory li ...

  7. Codeforces Round #275 Div.1 B Interesting Array --线段树

    题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...

  8. Codeforces Round #275 (Div. 2)

    A. Counterexample 题意:给出l,r,找出使得满足l<a<b<c<r,同时满足a,b的最大公约数为1,b,c的最大公约数为1,且a,b的最大公约数不为1 因为题 ...

  9. Codeforces Round #275 (Div. 2) 题解

    A 题: 说的是在(LR) 之间找出ab互质 bc 互质 ac 不互质的 3个数 数据量小直接暴力 #include <iostream> #include <cstdio> ...

随机推荐

  1. quailty's Contest #1 道路修建 EXT(启发式合并)

    题目链接  道路修建 EXT 考虑并查集的启发式合并,合并的时候小的子树的根成为大的子树的根的儿子. 可以证明这样整棵树的深度不会超过$logn$. 两个根合并的时候,产生的新的边的边权为当前的时间. ...

  2. Struts的线程安全

    Servlet/JSP技术和ASP.PHP等相比,由于其多线程运行而具有很高的执行效率.由于Servlet/JSP默认是以多线程模式执行的,所以,在编写代码时需要非常细致地考虑多线程的安全性问题.然而 ...

  3. 搭建基于asp.net的wcf服务,ios客户端调用的实现记录

    一.写wcf 问题: 1.特定的格式 2.数据绑定 3.加密解密 二.发布到iis 问题: 1.访问权限问题,添加everyone权限 访问网站时:http://localhost/WebbUploa ...

  4. espresso Seekbar

    package test.utils; import android.support.test.espresso.PerformException; import android.support.te ...

  5. 设计模式之状态模式(PHP实现)

    github地址:https://github.com/ZQCard/design_pattern /** * 在状态模式(State Pattern)中,类的行为是基于它的状态改变的.这种类型的设计 ...

  6. Python中的*args和**kwargs的理解与用法

    一.简述 1.*args和**kwargs 这两个是python中方法的可变参数. 2.*args表示任何多个无名参数,它是一个tuple: 3.**kwargs表示关键字参数,它是一个dict.并且 ...

  7. python获取输入参数

    python获取输入参数 学习了:https://www.cnblogs.com/angelatian/p/5832448.html import sys模块: len(sys.argv)参数个数 s ...

  8. P6 EPPM 安装和配置指南

    In This Section Installation and Configuration Guide Manual Installation Guides P6 Professional Inst ...

  9. 【HTML 元素】嵌入图像

    img元素允许我们在HTML文档里嵌入图像. 要嵌入一张图像需要使用src和alt属性,代码如下: <img src="../img/example/img-map.jpg" ...

  10. CMake 从文件路径中提取文件名

    FILE(GLOB_RECURSE SRC_FILES "*.c" "*.cc" "*.cpp" "*.h" " ...