hbmy周赛1--C

C - Exam

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u

Submit Status

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 tok?-?1.

If there are several possible answers, output any of them.

Sample Input

Input

6

Output

6
1 5 3 6 2 4

Input

3

Output

2
1 3

#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n==1)
	{
		cout << 1<< endl << 1<< endl;
	}
	if (n==2)
		cout << 1<< endl << 1<< endl;
	if (n==3)
	{
		cout << 2<< endl<< 1<< " "<< 3<< endl;
	}
	if (n == 4)
	{
		cout <<4<< endl;
		cout << 2 << " "<< 4<< " "<< 1<<" "<< 3<<endl;
	}
	if (n==5)
		cout << 5<<endl<<1<<" "<< 4<< " "<< 2<< " "<< 5<< " "<<3<< endl;
	if (n>5)
	{
		cout << n<< endl;
		cout << n<< " ";
		for (int i=1; i<n; i++)
		{
			if (i%2!=0)
				printf("%d ",i);
		}
		for (int j=2; j<n; j++)
		{
			if (j%2==0)
				printf("%d ",j);
		}
		cout << endl;
	}
	return 0;
}

时间: 2024-10-11 16:02:04

hbmy周赛1--C的相关文章

hbmy周赛1--D

D - Toy Cars Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The proces

hbmy周赛1--E

E - Combination Lock Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the t

HLJU周赛5解题报告

Problem A: 求第K大数 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 81  Solved: 32 [Submit][Status][Web Board] [Edit] [TestData] Description 一天,喜欢看电影的DoubleQ 和 XXZ 来到一个神奇的电影院,这个电影院可以同时放映n部电影,每部电影都有相应的票价xi,面对着杀破狼2,侏罗纪世界,少年班等等好看的电影,他们最后商量,看票价第K大的电影,但是由于电影

CSDN 轻松周赛赛题:能否被8整除

轻松周赛赛题:能否被8整除 题目详情 给定一个非负整数,问能否重排它的全部数字,使得重排后的数能被8整除. 输入格式: 多组数据,每组数据是一个非负整数.非负整数的位数不超过10000位. 输出格式 每组数据输出一行,YES或者NO,表示能否重排它的全部数字得到能被8整除的数.注意: 重排可以让0开头. 答题说明 输入样例   610 122 输出样例   YES NO 解释   第一个数可以变为016 , 160 解题:很水的一道题...思路很简单,1000是能被8整除的,所以一千的倍数都能被

2015 年 JXNU_ACS 算法组寒假第二次周赛

2015 年 JXNU_ACS 算法组寒假第二次周赛 比赛链接:http://acm.hdu.edu.cn/diy/contest_show.php?cid=26246 Start Time : 2015-02-01 13:00:00 End Time : 2015-02-01 17:30:00 终榜:http://acm.hdu.edu.cn/diy/contest_ranklist.php?cid=26246&page=1 这次比赛考查的知识都很基础,甚至还有几道就是C语言基础(比如1006

周赛 POJ 2250 Compromise

Description In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countries (maybe except for Luxembourg). To enforce that Germa

周赛 POJ 3934 Queue

Description Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the dinning hall is a little bit far away from the classroom, those n kids have to walk in line to the dinning hall every day. When they are walking in line, if a

周赛 POJ 3546 The Dragon of Loowater

Description Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predators, the geese populati

周赛 POJ 2245 Lotto

Description In the German Lotto you have to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chance of winning - is to select a subset S containing k (k > 6) of these 49 numbers, and the