题目传送门

 /*
构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放。因为是绝对差值,从n开始一下一上,
这样保证不会超出边界并且以防其余的数相邻绝对值差>k
*/
/************************************************
Author :Running_Time
Created Time :2015-8-2 9:20:01
File Name :B.cpp
*************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; typedef long long ll;
const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
bool vis[MAXN];
int a[MAXN]; int main(void) { //Codeforces Round #275 (Div. 2) C. Diverse Permutation
int n, k;
while (scanf ("%d%d", &n, &k) == ) {
if (k == ) {
for (int i=; i<=n; ++i) {
printf ("%d%c", i, (i==n) ? '\n' : ' ');
}
continue;
}
memset (vis, false, sizeof (vis));
int j = ; a[] = n; vis[a[]] = true; bool flag = false;
for (int i=k; i>=; --i) {
if (flag) {
a[j] = a[j-] + i; vis[a[j]] = true; ++j; flag = !flag;
}
else {
a[j] = a[j-] - i; vis[a[j]] = true; j++; flag = !flag;
}
}
int p = n;
for (int i=j; i<n; ++i) {
for (int k=p; k>=; --k) {
if (!vis[k]) {
a[i] = k; vis[k] = true; p = k; break;
}
}
}
for (int i=; i<n; ++i) {
printf ("%d%c", a[i], (i==n-) ? '\n' : ' ');
}
} return ;
}

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

  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

    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 #302 (Div. 2) B Sea and Islands

    题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...

  6. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  7. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  8. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  9. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

随机推荐

  1. Ajax核心知识(2)

    对于Ajax核心的东西需要在进行总结提炼一下: xmlHttp对象. 方法:xml.responseText获取后台传递到前台的数据,经常性的使用var object=xml.responseText ...

  2. [bzoj1059][ZJOI2007]矩阵游戏_二分图最大匹配

    矩阵游戏 bzoj-1059 ZJOI-2007 题目大意:给定一个n*n的棋盘,上面有一些格子被染黑,剩下都是白色.你每次可以交换两列或者两行,问你能否通过一系列操作使得棋盘的主对角线上的格子全是黑 ...

  3. Ubuntu 16.04安装WinRAR/7-Zip(基于CrossOver)

    基于CrossOver的WinRAR/7-Zip有如下缺点: 1.不能像Windows那样右键菜单解压 可以解决的问题: 1.可以使用提供的浏览工具进行文件选择再解压,只是在操作上多一步. 2.类似百 ...

  4. PopupMenu的演示样例

    弹出菜单是停靠在一个View上的一个模式菜单. 假设View对象下方有空间,那么弹出菜单将显示在停靠对象的下方,否则会显示在上方. 这是很实用的: 源代码地址:http://download.csdn ...

  5. laravel 实时facade

    实时facade 创建一个目录叫services 创建一个weibo类 <?php namespace App\Services; class weibo { protected $http; ...

  6. Vuzzer自动漏洞挖掘工具简单分析附使用介绍

    Vuzzer 是由计算机科学机构  Vrije Universiteit Amsterdam.Amsterdam Department of Informatics 以及 International ...

  7. C++学习之构造函数中的异常处理

    构造函数中可不可以抛出异常?当然可以.从语法上来说,是可以的:从实际情况来看,现在的软件系统日渐庞大和复杂,很难保证 Constructor 在执行过程中完全不发生一点异常. 那么,如果构造函数中抛出 ...

  8. 动态生成页面(一)——ASP.NET中Literal使用

    在页面中加入内容时,假设是静态内容.无需使用容器,能够直接将标记作为HTML直接加入到页面中:可是,假设是动态内容,则必须借助容器将内容加入到页面中.典型的容器有:Label控件.Literal控件. ...

  9. 剑指offer面试题18-树的子结构

    题目: 输入两颗二叉树A和B,推断B是不是A的子结构. 树的结构例如以下: package com.aii.algorithm; public class TreeNode { int value; ...

  10. Android学习笔记-tween动画之xml实现

    继上篇tween动画的java实现:http://www.cnblogs.com/fengtengfei/p/3957800.html, 这里我接着介绍一下tween动画的xml实现的方法,   首先 ...