A. Exam

A. Examtimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputAnexamfor n studentswilltakeplaceinalongandnarrowroom,

A.

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 to k - 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

解题说明:此题只需要让数字不连续出现,对于1-4的情况可以简单排列,5以上就可以让奇偶分开来排列。

#include <stdio.h>

int main()
{
	 int h, i, j, n;
	 scanf("%d", &n);
	 if(n==1||n==2)
	 {
		 printf("1\n1");
	 }
	 else if(n==3)
	 {
		 printf("2\n1 3");
	 }
	 else if(n==4)
	 {
		 printf("4\n2 4 1 3");
	 }
	 else
	 {
		  printf("%d\n1", n);
		  for(i=3;i<=n;i+=2)
		  {
			  printf(" %d", i);
		  }
		  for(i=2;i<=n;i+=2)
		  {
			  printf(" %d", i);
		  }
	 }
	 return 0;
}

今天的文章A. Exam分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/33582.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注