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

时间:2021-09-06 11:55:04

A. Exam

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/534/problem/A

Description

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.

Sample Input

input1
6
input2
3
 

Sample Output

6
1 5 3 6 2 4
 
2
1 3

HINT

题意

啊,学生要去参加考试啦~

给你n,表示有n个学生,编号为i的人和编号为i+1和编号为i-1的人关系很好,所以他们就不能坐在一起

然后就问你,在合法的情况下,最多坐几个人,怎么坐?

题解:

啊,我们奇数先坐着,偶数再坐,就这样,保证相邻的至少差2,前四个我们特判就好啦!

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//************************************************************************************** int main()
{
int n;
cin>>n;
vector<int> ans;
for(int i=;i<=n;i+=)
ans.push_back(i);
for(int i=;i<=n;i+=)
ans.push_back(i);
if(n==)
{
cout<<""<<endl;
cout<<""<<endl;
return ;
}
if(n==)
{
cout<<""<<endl;
cout<<"1 3"<<endl;
return ;
}
if(n==)
{
cout<<""<<endl;
cout<<"3 1 4 2"<<endl;
return ;
}
cout<<ans.size()<<endl;
for(int i=;i<ans.size();i++)
cout<<ans[i]<<" ";
}