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 ...
随机推荐
- Jrebel简单的热部署一个web工程
前言:博主最近在做Hybris开发,漫长的启动时间大大的拖累了项目的进度,而Jrebel的出现就是为了减少项目重启的时间或者说修改了代码后直接不用重启就可以看到修改的结果,但是Hybris的部署一直没 ...
- React Native出现"Native module cannot be null"问题
经查跟PushNotification有关,需要手动完成Linking. 两步解决此问题: 配置Linking Libraries:https://facebook.github.io/react-n ...
- Oracle12c_安装1——准备工作
1.建议用户和组 su root #切换到root groupadd oinstall #创建用户组oinstall groupadd dba #创建用户组dba useradd -g oinstal ...
- requireJS(版本是2.1.15)学习教程(一)
一:为什么要使用requireJS? 很久之前,我们所有的JS文件写到一个js文件里面去进行加载,但是当业务越来越复杂的时候,需要分成多个JS文件进行加载,比如在页面中head内分别引入a.js,b. ...
- JavaScript的DOM编程--12--innerHTML属性
innerHTML属性: 1). 浏览器几乎都支持该属性, 但不是 DOM 标准的组成部分. innerHTML 属性可以用来读, 写某给定元素里的 HTML 内容 <html> < ...
- MySQL数据库学习02: SELECT语句
声明:本篇文章大多数内容出自<MySQL必知必会>,仅供学习参考,勿作他用! 第4章 检索数据 4.1 SELECT语句 SELECT子句用于检索数据库中的表数据.它几乎是MySQL中最常 ...
- linux odbc连接sql server2014
首先坑爹呀!由于配置Zabbix 用到这个,网上资料一顿搜,一顿报错,调各种参数,依然无法连接,我竟无言以对: 这个只是项目的一小部分,只提供成功案例,没做深入研究,可以让遇到的兄弟少走弯路: 建议第 ...
- C#设计模式之一单例模式(Singleton Pattern)【创建型】
一.引言 看了李建忠老师的讲的设计模式已经有一段时间了(这段时间大概有一年多了),自己还没有写过自己的.有关设计模式的文章.这次想写一些关于设计模式的文章,用自己的理解和代码来写,算是复习一遍 ...
- QQ音乐API-借他人之力实现我的音乐盒
好久没有写博客了,最近升级做爸爸了,很开心的事情.内心又很忧郁,怎么能给媳妇和儿子一个相对好的物质经济条件.现在什么都没有的我,至少还有你们. 话不多说了,这篇博客还是和自己用vue做web app相 ...
- STM32f103x IAP远程升级小结
最近在面试的时候遇到一个关于IAP远程程序升级的问题,由于之前所做的项目没有涉及到远程升级需求,当时一脸懵呆,不过回答的还是不错的,今天针对STM32F103系列调试了IAP的程序,这里做一下小结,如 ...