题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation

题意:一串排列1~n。求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个。求序列、

思路:1~k+1。构造序列前段,之后直接输出剩下的数。前面的构造能够依据,两项差的绝对值为1~k构造。

AC代码:

#include <stdio.h>
#include <string.h>
int ans[200010];
bool vis[100010];
int n,mark;
int iabs(int a)
{
if(a<0) return -a;
return a;
}
int main()
{
int i,cnt,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
int x,y;
memset(vis,0,sizeof vis);
ans[0]=1;
x=1,y=k+1;
cnt=k;
for(i=1; i<=k; i++,cnt--)
{
int temp=ans[i-1]+cnt;
if(temp>k+1)
temp=ans[i-1]-cnt;
else if(vis[temp])
temp=ans[i-1]-cnt;
ans[i]=temp;
vis[temp]=true;
}
for(i=k+1; i<n; i++)
ans[i]=i+1;
for(i=0; i<n-1; i++)
printf("%d ",ans[i]);
printf("%d\n",ans[i]);
}
return 0;
}

Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)的更多相关文章

  1. 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 ...

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

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

  3. 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 ...

  4. Codeforces Round #486 (Div. 3) A. Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

  5. Codeforces Round #275 (Div. 2)

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

  6. Codeforces Round #275 (Div. 2) A,B,C,D

    A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...

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

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

  8. (原创)Codeforces Round #550 (Div. 3) A Diverse Strings

    A. Diverse Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #275 (Div. 2) C

    题目传送门:http://codeforces.com/contest/483/problem/C 题意分析:题目意思没啥好说的. 去搞排列列举必须TLE.那么就想到构造. 1.n.2.n-1.3.n ...

随机推荐

  1. 一天一个类--ArrayList之一

    今天开始打算将JDK7种的一些类的源码分析一下,笔者认为了解源码就是了解其实现过程,这是非常重要的,而不是简单的记住方法的使用,关键是了解其思想和目的这才是重要的.所以笔者决定首先将从一些容器下手.[ ...

  2. 线程:Message和Runnable

    原文地址http://blog.csdn.net/flowingflying/article/details/6370184 程序需要相应用户的操作,最要能在200ms(0.2s)之内,如果超过5秒没 ...

  3. Cocos2d-x 3.2 大富翁游戏项目开发-第七部分 获取角色路径_3

    点击下载代码   http://download.csdn.net/detail/lideguo1979/8291803 新建一个类RouteNavigation,定义getPath()方法.用来获取 ...

  4. Linux安装完Tomcat后无法登陆管理界面

    今天在Linux中安装完Tomcat后无法登陆Tomcat的管理界面,也就无法利用Tomcat管理界面来部署项目. 在Windows中一般配置完Tomcat后,只要在[conf]目录下的“tomcat ...

  5. c语言,enum

    在设置错误代号时,使用enum比宏更好看. #include <stdio.h> typedef enum { retOK = 0, errComInterruption = 0x1000 ...

  6. 如何解决android logcat不打印信息在android开发中

    用eclipse进行android开发中经常遇到logcat无任何信息输出,这给我们调试程序带来很大的不便.解决办法:window-->show view-->选择android下的dev ...

  7. 恢复PasswordChar 默认值、取消密码框设置

    //三种都是清空 this.textBox1.PasswordChar = new char(); this.textBox1.PasswordChar = '\0'; this.textBox1.P ...

  8. 基于visual Studio2013解决面试题之0610删除重复字符串

     题目

  9. 人人网javascript面试题

    JavaScript面试题要求:以下题目必须从一至四题中,选出三道题,使用原生代码实现,不可使用任何框架,第五题为选作题. 一.  在页面的固定区域内实现图片的展示       <ignore_ ...

  10. Linux下的链接文件

    整理自<鸟哥的Linux私房菜>,整理者:华科小涛http://www.cnblogs.com/hust-ghtao/ Linux中的链接文件分为两种:硬链接和软链接.软链接(symbol ...