题目链接:http://codeforces.com/problemset/problem/483/C

题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| 恰好有 k 个不同的数。注意,p1, p2, ..., pn 每个数是不相等的,而且不大于 n。

构造题,这个通过手动很容易知道答案。又献上我的恶心涂鸦~~~看完之后会发现其实很简单,好像比 B 还要简单。

只要红色的竖线前面满足不同的差值恰好有 k 个即可,上面的“+”“-” 是规律来的。竖线后面的差值是清一色等于 1 的。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; int main()
{
int n, k;
while (scanf("%d%d", &n, &k) != EOF)
{
if (k == )
{
for (int i = ; i <= n; i++)
printf("%d ", i);
printf("\n");
}
else
{
printf("");
int st = ;
int interval = k;
for (int i = ; i < k+; i++, interval--)
{
st += (i& ? interval : -interval);
printf(" %d", st);
}
for (int i = k+; i <= n; i++)
printf(" %d", i);
printf("\n");
}
}
return ;
}

codeforces 483C.Diverse Permutation 解题报告的更多相关文章

  1. CodeForces 483C Diverse Permutation

    Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  2. Codeforces Round 665 赛后解题报告(暂A-D)

    Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...

  3. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  4. codeforces C. Diverse Permutation

    C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #277.5 解题报告

    又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...

  6. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

  7. codeforces B. Levko and Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这 ...

  8. codeforces B. Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/359/B 题目意思:给定n和k的值,需要构造一条长度为2n(每个元素取值范围只能是[1,2n])且元素各不 ...

  9. codeforces B. Simple Molecules 解题报告

    题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...

随机推荐

  1. 【HDU 4150】Powerful Incantation

    题 题意 给你s1,s2两个字符串,求s1中有多少个s2 代码 #include<stdio.h> #include<string.h> int t,len1,len2,pos ...

  2. CSU 1113 Updating a Dictionary

    传送门 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Description In th ...

  3. 【基础语法】a++与++a的区别

    package com.on.learn.e2; /** * @author lj * 自增:a++与++a a++是指本行表达式不使用a自增后的值,++a是指本行开始就已经使用a自增后的值 * */ ...

  4. input type="submit" 和"button"有什么区别?

    http://www.zhihu.com/question/20839977 在一个页面上画一个按钮,有四种办法: <input type="button" /> 这就 ...

  5. sql-server数据库中利用触发器实现表与表之间的级联删除

    create trigger Delete_Student --创建一个触发器 on student instead of delete as declare @sno varchar() selec ...

  6. 织梦DedeCms去掉栏目页面包屑导航最后的分隔符“>”

    织梦DedeCms的面包屑导航调用标签{dede:field name=’position’ /},在栏目页里调用的面包屑导航,最后会出现分割符号“>”,如:主页 > DedeCms 模板 ...

  7. Jquery 扩展获取RUL参数

    //扩展获取url $.extend({ getUrlVars: function () { var vars = [], hash; var hashes = window.location.hre ...

  8. Windows下安装配置SubVersion的简明步骤

    [使用的安装程序和文档说明] svn-1.4.0-setup.exe:Subversion服务端1.4.0安装程序: SubService.rar:  SubServe服务Windows辅助工具; T ...

  9. 关于笔记本安装双系统windows and linux

    ps1.安装完成后,补充下如何设在win7为默认启动系统, 大家也都知道,在linux 运行当软件都是以配置文件来设置参数当,当然grub菜单也不例外, 修改菜单可以进入grub.conf [root ...

  10. artEditor增加表单提交功能

    摘要: artEditor.js是一款移动端的富文本编辑器,支持图片上传,后面会增加表情.小视频等功能.最近有朋友反馈artEditor是否支持表单提交,当然是支持的,在未开发该功能之前,你可以像下面 ...