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集群添加新节点步骤

    1.在新节点中进行操作系统配置,包括主机名.网络.防火墙和无密码登录等. 2.在所有节点/etc/host文件中添加新节点 3.把namenode的有关配置文件复制到该节点 4.修改master节点s ...

  2. ntpdate:no server suitable for synchronization found

    Question: 在使用ntpdate同步时间时,出现了no server suitable for synchronization found的报错. 通过ntpdate -d s2m.time. ...

  3. 救援行动(save) (BFS)

    时间限制: 1 Sec  内存限制: 64 MB提交: 42  解决: 9[提交][状态][讨论版] 题目描述 Angel被人抓住关在一个迷宫了!迷宫的长.宽均不超过200,迷宫中有不可以越过的墙以及 ...

  4. 黑马程序员——JAVA基础之简述面向对象,类,变量,匿名对象

    ------- android培训.java培训.期待与您交流! ---------- 面向对象: 面向对象是相对面向过程而言 面向对象和面向过程都是一种思想 面向过程 强调的是功能行为 面向对象 将 ...

  5. Valgrind简单用法

    Valgrind的主要作者Julian Seward刚获得了今年的Google-O'Reilly开源大奖之一──Best Tool Maker.让我们一起来看一下他的作品.Valgrind是运行在Li ...

  6. 将HTML段赋值给PHP变量的便捷方法,不使用转义字符

    <?php $b='12'; $a=<<<sss <html> <head> </head> <body> <i>& ...

  7. [unity3d程序] 纹理扩散

    纹理扩散适合与做游戏的背景(卷轴效果),原理就是让材质贴图动起来(循环运动),代码很简单希望对大家有用 1 2 3 4 5 6 7 8 9 10 11 12 13 // Scroll main tex ...

  8. java_常用数据类型转换基础篇

    一.java基本数据类型 1.java基本数据类型可分四类八中 第一类:整形:byte.short.int.long 第二类:浮点型:float(单精度) .double(双精度) 第三类:逻辑类型: ...

  9. OpenJudge-计算点的距离并排序

    /*===================================== 距离排序 总时间限制: 1000ms 内存限制: 65536kB 描述 给出三维空间中的n个点(不超过10个),求出n个 ...

  10. 使用maven编译dubbo,导入eclipse(其他maven开源项目编译类似)

    dubbo github下载地址:https://github.com/alibaba/dubbo 相关文档:http://dubbo.io/ 使用maven编译dubbo,导入eclipse(其他m ...