Exam
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 tok - 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,特判一下,先输出偶数再输出奇数。

 #include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using namespace std; int main(void)
{
int n,i; while(cin >> n)
{
if(n == || n == )
cout << "" << endl << "" << endl;
else if(n == )
cout << "" << endl << "1 3" << endl;
else
{
cout << n << endl;
for(i = ;i <= n;i += )
cout << i << ' ';
for(i = ;i <= n;i += )
if(i + > n)
cout << i;
else
cout << i << ' ';
cout << endl;
}
} return ;
}

CF Exam (数学)的更多相关文章

  1. hdu 4473 Exam 数学

    思路: 将条件转化为满足abc<=n的abc的数目. 1.3个数相等时,为 A; 2.有2个数相等时,为 B; 3.都不相等时,为 C. 则结果为A+3*B+6*C. 代码如下: #includ ...

  2. CF Spreadsheets (数学)

    Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input ...

  3. linux文件管理之解压缩

    文件的压缩与解压缩 Linux文件压缩工具有:gzip.bzip2.rar.7zip.lbzip2.xz.lrzip.PeaZip.arj等.============================= ...

  4. 第18章-x86指令集之常用指令

    x86的指令集可分为以下4种: 通用指令 x87 FPU指令,浮点数运算的指令 SIMD指令,就是SSE指令 系统指令,写OS内核时使用的特殊指令 下面介绍一些通用的指令.指令由标识命令种类的助记符( ...

  5. 【JVM源码解析】模板解释器解释执行Java字节码指令(上)

    本文由HeapDump性能社区首席讲师鸠摩(马智)授权整理发布 第17章-x86-64寄存器 不同的CPU都能够解释的机器语言的体系称为指令集架构(ISA,Instruction Set Archit ...

  6. CF 990A. Commentary Boxes【数学/模拟】

    [链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...

  7. CF #305(Div.2) D. Mike and Feet(数学推导)

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  8. cf.295.C.DNA Alignment(数学推导)

    DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. CF Amr and Pins (数学)

    Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

随机推荐

  1. Can jxta be used to develop online card game (p2p style)?

    Can jxta be used to develop online card game (p2p style)? https://www.java.net//node/677134 I am new ...

  2. (转)关于CoreData的一个工具Mogenerator的使用

    最近看到用CoreData时使用的工具Mogenerator,发现网上介绍其具体使用的不多,特此简单整理一下,关于CoreData这里就不具体说了,使用就用MagicalRecord,用起来真是太方便 ...

  3. Gym 100507C Zhenya moves from parents (线段树)

    Zhenya moves from parents 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/C Description Z ...

  4. 【C语言】-一维数组

    数组: 数组是一系列相同类型的有序数据的集合,数组中的每一个元素都是同一个数据类型,所有元素共用一个名字,用下标来区别数组中的每一个元素. C语言中,数组属于构造数据类型.一个数组中含有多个数组元素, ...

  5. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

  6. delphi读取excel

    简单的例子 procedure TForm1.Button1Click(Sender: TObject); var ExcelApp,MyWorkBook: OLEVariant; begin ope ...

  7. Serializable 序列化使用限制

    序列化不能跨语言 如果单纯为了传数据,完全可以被json代替.

  8. Simple guide to Java Message Service (JMS) using ActiveMQ

    JMS let’s you send messages containing for example a String, array of bytes or a serializable Java o ...

  9. freemarker截取字符串subString

    转至:http://fengzhijie1103.iteye.com/blog/1142918 freemarker截取字符串其实和JAVA语法是差不多了,也有substring 方法       如 ...

  10. update多表更新的2种方式

    update t1 set TermBeginQty =isnull((select top 1 JiaoPlusQty from WMS_RptMaterialPutDaily r where t1 ...