An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.

Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.

Input

A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.

Output

In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.

In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true:|ai - ai + 1| ≠ 1 for all i from 1 to k - 1.

If there are several possible answers, output any of them.

Sample test(s)
input
6
output
6
1 5 3 6 2 4
input
3
output
2
1 3 直接特判n<=4
对于n>4,肯定是可以全部出来的
构造:先输出所有奇数,再输出所有偶数
如n=7,则输出:
7
1 3 5 7 2 4 6
#include<cstdio>
#include<iostream> using namespace std; int main()
{
int n;
cin>>n;
if(n== || n==){
cout<<"1\n1"<<endl;
}
else if(n==){
cout<<"2\n1 3"<<endl;
}
else if(n==){
cout<<"4\n2 4 1 3"<<endl;
}
else{
cout<<n<<endl;
for(int i=;i<=n;i+=)
cout<<i<<" ";
for(int i=;i<=n;i+=){
cout<<i;
if(i==n- || i==n)
cout<<endl;
else
cout<<" ";
}
}
return ;
}

CF534A Exam 构造的更多相关文章

  1. Codeforces Round #298 (Div. 2) A. Exam 构造

    A. Exam Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/A Des ...

  2. MVC 构造新Model实现内容搜索

    当前在使用MVC开发一个网站,习惯了使用ASP.NET中控件,转到MVC之后突然对于页面和后台代码的传值感觉无从下手.花了点时间在网上看了写帖子后,想到了一个方法,重新构造一个新Model, 然后利用 ...

  3. Codeforces Round #335 (Div. 2) D. Lazy Student 构造

    D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...

  4. 【Java】-NO.20.Exam.1.Java.1.001- 【1z0-807】- OCEA

    1.0.0 Summary Tittle:[Java]-NO.20.Exam.1.Java.1.001-[1z0-807] Style:EBook Series:Java Since:2017-10- ...

  5. Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造

    题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...

  6. Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  7. codeforces1016 D. Vasya And The Matrix(思维+神奇构造)

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. Vasya And The Matrix CodeForces - 1016D (思维+构造)

    Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the ma ...

  9. 学习笔记:Maven构造版本号的方法解决浏览器缓存问题

    需要解决的问题 在做WEB系统开发时,为了提高性能会利用浏览器的缓存功能,其实即使不显式的申明缓存,现代的浏览器都会对静态文件(js.css.图片之类)缓存.但也正因为这个问题导致一个问题,就是资源的 ...

随机推荐

  1. hadoop常用管理员命令

    hadoop job -list 列出正在运行的job hadoop job -kill kill掉job hadoop fsck 检查HDFS坏快 hadoop dfsadmin -report检查 ...

  2. 【NOIP2007】矩阵取数

    因为傻逼写错高精度搞了一下午浪费好多时间,好想哭qaq 原题: 帅帅经常更同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij据为非负整数.游戏规则如下: 1. 每次取数时须从每 ...

  3. sersync2 实时同步配置

    在同步服务器上开启sersync,将监控路径中的文件同步到目标服务器,因此需要在同步服务器配置sersync,在同步目标服务器配置rsync. 一.同步目标服务器配置rsync # rpm -qa | ...

  4. solr 主从模式和solrcloud集群模式

    主从模式 主节点有单点故障问题:没有主从自动切换,没有failover,主机down掉了的话,整个数据变成只读.并且需要一台机单独做索引,浪费资源,所有数据都需要在这台机器上单独存在一份,索引变化较大 ...

  5. easyUI之window

    window组件是一个可拖动.浮动的面板,用于显示信息.内容可用 href或ajax获取. window是一个显示窗口,同时也可以显示layout的功能(也就是创建复合的组合窗口),如 <div ...

  6. 用JavaScript往DIV动态添加内容

    参考:http://zhidao.baidu.com/link?url=6jSchyqPiEYCBoKdOmv52YHz9r7MTBms2pK1N6ptOX1kaR2eg320mlW1Sr6n36hp ...

  7. .htaccess中301强制跳转到带www前缀或不带www的域名

    相信很多站长朋友都有这样的的问题出现.即带www前缀的域名与不带www前缀的顶级域名收录情况是不同的.这个问题主要是由于搜索引擎对于顶级域名与二级域名权重判定不同造成的.毫无疑问地,唯一的域名能够给你 ...

  8. SqlParameter设定的value值为0时、调用的存储过程获取到的值却为null解决方法

    原C#代码如下: if (query != null) { switch (query.MethodFlag) { //进出口退补税额统计表 case (int)EnumClassifyCorrect ...

  9. mysql 查看最大连接数 设置最大连接数

    方法一:进入MYSQL安装目录 打开MYSQL配置文件 my.ini 或 my.cnf查找 max_connections=100   修改为 max_connections=1000 服务里重起MY ...

  10. 使用原生js写ajax

    // 使用原生js 封装ajax // 兼容xhr对象 function createXHR(){ if(typeof XMLHttpRequest != "undefined") ...