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 ...
随机推荐
- C# TreeView 控件的综合使用方法
1.概述 该篇文章开发使用的语言c#,环境visualstudio2010,sql数据库.主要内容包括: (1)treeView控件添加根节点.子节点的基本方法,节点的删除. (2)把treeView ...
- 栈和队列数据结构的相互实现[LeetCode]
栈是先进后出,队列是先进后出,这里讨论一下两种数据结构之间的相互实现. 一.用两个栈实现队列 我们用一个栈来实现队列的进队操作(栈A),用另一个栈来实现队列的出队操作(栈B). 1.入队列: 把元素放 ...
- tensorflow ckpt文件转caffemodel时遇到的坑
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ".PingFang SC"; color: #454545 } p.p2 ...
- Python学习(一):编写购物车
1.购物车流程图: 2.代码实现: #!/usr/bin/env python #coding=utf-8 ChoiceOne =''' 1.查看余额 2.购物 3.退出 ''' ChoiceTwo ...
- fdisk 命令详解
fdisk 作用: 查看磁盘实体使用情况,也可对硬盘分区. 选项: -b 分区大小 -l 列出指定的外围设备的分区表状况 -s 分区编号, 将指定的分区大小输出到标准输出上, 单位为区块 -u ...
- JavaScript函数(二)
在前面我们已经对函数作了简单的介绍,比如函数的定义.函数的声明.函数的调用和函数的传参等.本节将进一步介绍函数的应用,深度理解函数的各种使用. 函数是一个对象,每个函数时Function类型的一个实例 ...
- DCL的失效:现实与初衷的背离
最近看了Brian Goetz写的一篇有关DCL的文章:Double-checked locking: Clever, but broken.( 2001年发表于JavaWorld上) 这篇文章讲述了 ...
- 浅谈OGNL表达式
OGNL(Object-Graph Navigation Language):对象视图导航语言 ${user.addr.name}这样的写法就叫对象视图导航 OGNL不仅可以视图导航,支持EL表达式更 ...
- [编织消息框架][netty源码分析]13 ByteBuf 实现类CompositeByteBuf职责与实现
public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements Iterable<ByteBuf ...
- 给yii架构的网站做Android客户端
网站未预留接口.给这类网站制作客户端就是模拟网页发送的post和get请求,然后获取服务器返回的数据. 1.在做客户端时先使用httpwatch分析浏览器发送的get和post请求的内容和URL.分析 ...