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
  1. 6
output
  1. 6
    1 5 3 6 2 4
input
  1. 3
output
  1. 2
    1 3
  2.  
  3. 直接特判n<=4
    对于n>4,肯定是可以全部出来的
    构造:先输出所有奇数,再输出所有偶数
    n=7,则输出:
    7
    1 3 5 7 2 4 6
  1. #include<cstdio>
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n;
  9. cin>>n;
  10. if(n== || n==){
  11. cout<<"1\n1"<<endl;
  12. }
  13. else if(n==){
  14. cout<<"2\n1 3"<<endl;
  15. }
  16. else if(n==){
  17. cout<<"4\n2 4 1 3"<<endl;
  18. }
  19. else{
  20. cout<<n<<endl;
  21. for(int i=;i<=n;i+=)
  22. cout<<i<<" ";
  23. for(int i=;i<=n;i+=){
  24. cout<<i;
  25. if(i==n- || i==n)
  26. cout<<endl;
  27. else
  28. cout<<" ";
  29. }
  30. }
  31. return ;
  32. }
  1.  

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. Javascript对象属性与方法汇总

    Javascript对象属性与方法汇总 发布时间:2015-03-06 编辑:www.jquerycn.cn 详细介绍下,javascript对象属性与对象方法的相关知识,包括javascript字符 ...

  2. DELPHI相应鼠标滚轮

    在鼠标的MouseWheel事件里写入以下内容 if WheelDelta < 0 then    SendMessage(scrollBox1.Handle, WM_VSCROLL, SB_L ...

  3. C# waitformultipleobjects()

    class WatchThread { [DllImport("kernel32.dll")] private static extern int CreateEvent(IntP ...

  4. VC++ 0xC0000005: Access violation.

    public: COptionDlg(CWnd* pParent = NULL); // 标准构造函数 virtual ~COptionDlg(); TCONFIG m_tCfg; // 对话框数据 ...

  5. jsonp 跨域原理详解

    JavaScript是一种在Web开发中经常使用的前端动态脚本技术.在JavaScript中,有一个很重要的安全性限制,被称为“Same-Origin Policy”(同源策略).这一策略对于Java ...

  6. 单例模式-ios

    #import <Foundation/Foundation.h> @interface UserContext : NSObject <NSCopying> @propert ...

  7. Viewpager图片自动轮播,网络图片加载,图片自动刷新

    package com.teffy.viewpager; import java.util.ArrayList; import java.util.concurrent.Executors; impo ...

  8. createdb test时报global/pg_filenode.map不存在

    实际上是存在的,看到说是ipv6占用了5432的端口号,看了一下的确是,将ipv6关闭重启系统即可. 下面是关闭ipv6的方法: 确认IPV6是否开启 在Linux下确认IPv6是否已经被启用,可以从 ...

  9. 021. asp.net两个DataSet数据集的合并

    protected void Page_Load(object sender, EventArgs e) { DataSet dsSource = new DataSet(); //创建源数据集 Da ...

  10. HtmlAgilityPack

    http://htmlagilitypack.codeplex.com/wikipage?title=Examples http://nuget.org/packages/HtmlAgilityPac ...