博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF Exam (数学)
阅读量:6680 次
发布时间:2019-06-25

本文共 2095 字,大约阅读时间需要 6 分钟。

 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 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 using namespace std;11 12 int main(void)13 {14 int n,i;15 16 while(cin >> n)17 {18 if(n == 1 || n == 2)19 cout << "1" << endl << "1" << endl;20 else if(n == 3)21 cout << "2" << endl << "1 3" << endl;22 else23 {24 cout << n << endl;25 for(i = 2;i <= n;i += 2)26 cout << i << ' ';27 for(i = 1;i <= n;i += 2)28 if(i + 2 > n)29 cout << i;30 else31 cout << i << ' ';32 cout << endl;33 }34 }35 36 return 0;37 }

 

转载于:https://www.cnblogs.com/xz816111/p/4438957.html

你可能感兴趣的文章
HTML中的<table>标签及其子元素标签,JS中DOM对<table>的操作
查看>>
在linux中执行wget命令提示 -bash: wget: command not found 解决方法
查看>>
MobPush推送证书制作
查看>>
springmvc源码解析之配置加载ContextLoadListener
查看>>
网站安全防护工作
查看>>
如何判断一个以太坊地址是不是合约?
查看>>
逆袭!? 期待下一个“BCH”出现
查看>>
opengl es3.0学习篇五:图元装配跟光栅化
查看>>
Qt之添加菜单项&状态栏
查看>>
负载均衡在分布式架构中是怎么玩起来的?
查看>>
Java程序员在工作的同时应该具备什么样的能力?
查看>>
Dubbo深入分析之Cluster层
查看>>
分析Padavan源代码,二
查看>>
WordPress的WPML外挂出问题恐出现安全漏洞
查看>>
Django 调试技巧
查看>>
Spring Boot和thymeleaf , freemarker , jsp三个前端模块的运用
查看>>
phalcon-入门篇3(优美的URL与Config)
查看>>
单表60亿记录等大数据场景的MySQL优化和运维之道
查看>>
sql学习笔记
查看>>
maven编译时出现There are test failures
查看>>