534A. Exam

A. 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=1、2、3、4时是特殊情况,特别输出就行了。


其余情况按奇偶分别输出肯定能全部排完。

WA了两次是因为n=4时没想到能这么排。。果然智商拙计。。

#include <iostream>
using namespace std;

int main(void)
{
	int n;
	cin>>n;
	if(n<=2)cout<<"1\n1\n";
	else if(n==3)cout<<"2\n1 3\n";
	else if(n==4)cout<<"4\n3 1 4 2\n";
	else
	{
		cout<<n<<"\n";
		for(int i=1 ; i<=n ; i+=2)
			if(i==1)cout<<i;
			else cout<<" "<<i;
		for(int i=2 ; i<=n ; i+=2)
			cout<<" "<<i;
		cout<<"\n";
	}
	return 0;
}


你可能感兴趣的:(C++,算法,ACM)