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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值