hbmy周赛1--C
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
6
6
1 5 3 6 2 4
3
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;
}
hbmy周赛1--C的更多相关文章
- hbmy周赛1--E
E - Combination Lock Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I6 ...
- hbmy周赛1--D
D - Toy Cars Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...
- hbmy周赛1--B
B - 改革春风吹满地 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- hbmy周赛1--A
Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ...
- 周赛-KIDx's Pagination 分类: 比赛 2015-08-02 08:23 7人阅读 评论(0) 收藏
KIDx's Pagination Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) S ...
- 2015浙江财经大学ACM有奖周赛(一) 题解报告
2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...
- Leetcode 第133场周赛解题报告
今天参加了leetcode的周赛,算法比赛,要求速度比较快.有思路就立马启动,不会纠结是否有更好的方法或代码可读性.只要在算法复杂度数量级内,基本上是怎么实现快速就怎么来了. 比赛时先看的第二题,一看 ...
- 牛客OI周赛9-提高组题目记录
牛客OI周赛9-提高组题目记录 昨天晚上做了这一套比赛,觉得题目质量挺高,而且有一些非常有趣而且非常清奇的脑回路在里边,于是记录在此. T1: 扫雷 题目链接 设 \(f_i\) 表示扫到第 \(i\ ...
- codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]
就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...
随机推荐
- dropout理解:1神带9坑
Dropout是深度学习中防止过拟合的一项非常常见的技术,是hinton大神在12年提出的一篇论文里所采用的方法.有传言hinton大神的数学功底不是很好,所以他所提出的想法背后的数学原理并不是很复杂 ...
- 搭建eclipse+tomcat开发环境
JDK 1.6 Eclipse IDE For JEE Version Tomcat 6.0 tomcatPluginV33 //eclipse平台上的插件,但它并不是tomcat本身,需要安装独立 ...
- 外卖app的header组件开发
1.webpack框架创建 # 全局安装 vue-cli $ npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue init webpa ...
- [解决方案]WebAPI+SwaggerUI部署服务器后,访问一直报错的问题
项目的背景:制作一批接口用来给前台app或者网站提供服务,因为WebApi是最近几年来比较流行和新颖的开发接口的方式,而且又属于轻型应用,所以选用它 部署的过程:建立了WebAPI项目并使用Swagg ...
- SpringBoot初步
1.创建maven 项目 quickstart类型 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- Python的文件及异常
1. Python的文件及异常 1.1 文件操作 1.1.1 从文件中读取数据 许多情况下,我们的信息是存储在文本中的.例如对用户行为的分析,用户访问系统或者网站的访问信息会被存储于文本中,然后对文本 ...
- Oracle PL/SQL Developer集成TFS进行团队脚本文件版本管理
对于传统的使用关系型数据库的大型软件产品,后台数据库的持续开发和维护可能会产生大量的脚本文件,针对这些脚本文件应该怎样比较方便的进行版本管理,以及如何快捷的在团队之间进行权限等协作管理呢?不同的数据库 ...
- vmware一步步安装centos
软件环境:vmware10.0破解版 centos版本:6.4 1.启动vmware,新建虚拟机,选择自定义安装 2,出现如下界面,保持默认,点击下一步 3.这个步骤要特别注意,选择“稍后安装”,我们 ...
- Nginx集群之SSL证书的WebApi令牌验证
目录 1 大概思路... 1 2 Nginx集群之SSL证书的WebApi令牌验证... 1 3 Openssl生成SSL证书... 2 4 编写.NE ...
- RGB颜色 对照表
来自为知笔记(Wiz)