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 to k - 1.

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

Sample test(s)

input

6

output

61 5 3 6 2 4

input

3

output

2 1 3



解题心得:
1、这个题感觉就是要给脑筋急转弯,要求任意从中选取尽量多的书,其中两个数的差要大于1,就是两个数不相邻就可以了。奇数和奇数不相邻,偶数和偶数不相邻,将奇数当数字大于5以后,奇数最大的数已经比偶数最小的数大了,就可以全部放下(例如1、2、3、4、5、6、7 可以排成1、3、5、7、2、4、6),小于五的特判就可以了。1就是1,2为1或者2,3为1、3,4为3、1、4、2。也就4比较难得判断,其他的都很简单。做题的时候多想想,想不通的时候换一个角度想想,或者从样例中的答案中找找规律也是可以的。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5010;
int a[maxn],b[maxn];
int n;
int main()
{
//1到4都特判就可以了
scanf("%d",&n);
if(n == 1 || n == 2)
printf("1\n1");
else if(n == 3)
printf("2\n1 3");
else if(n == 4)
printf("4\n3 1 4 2"); else
{
printf("%d\n",n);
for(int i=1; i<=n; i++)
if(i%2)
printf("%d ",i);
for(int i=1; i<=n; i++)
if(!(i%2))
printf("%d ",i);
}
return 0;
}


数学算法:CF534A-Exam(思维)的更多相关文章

  1. Scratch编程与高中数学算法初步

    scratch编程与高中数学算法初步 一提到编程,大家可能觉得晦涩难懂,没有一定的英语和数学思维基础的人,一大串的编程代码让人望而步,何况是中小学生.   Scratch是一款由麻省理工学院(MIT) ...

  2. 简单数学算法demo和窗口跳转,关闭,弹框

     简单数学算法demo和窗口跳转,关闭,弹框demo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...

  3. HDU 6651 Final Exam (思维)

    2019 杭电多校 7 1006 题目链接:HDU 6651 比赛链接:2019 Multi-University Training Contest 7 Problem Description Fin ...

  4. CF534A Exam 构造

    An exam for n students will take place in a long and narrow room, so the students will sit in a line ...

  5. 数学算法:poweroj1026-丑数(根据固定倍数得到从小到大的序列)

    题目: 1026: 丑数 Time Limit: 1000 MS Memory Limit: 65536 KB Total Submit: 257 Accepted: 112 Page View: 1 ...

  6. Codeforces Round 56-C. Mishka and the Last Exam(思维+贪心)

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. noip201403螺旋矩阵【普及组】数学算法

    思路如下: 1.输入n>>a>>b; 2.用一个循环缩小范围求出a,b所示的数所在的圈数q; 3.再一个循环求出圈数q的第1个数的值sum; 4.用四个if判断a,b所示的数在 ...

  8. [原][c++][数学]osg常用图形数学算法小结

    1.cos趋近 // a reasonable approximation of cosine interpolation double smoothStepInterp( double t ) { ...

  9. codeforces Round #440 C Maximum splitting【数学/素数与合数/思维/贪心】

    C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. Xpath定位绝密版本

    xpath的作用就是两个字“定位”, 运用各种方法进行快速准确的定位,推荐两个非常有用的的firefox工具:firebug和xpath checker 在 XPath 中, 有七种类型的节点:元素. ...

  2. Java实例学习——企业进销存管理系统(4)

    Java实例学习——企业进销存管理系统(4) (本实例为书上实例,我所记录的是我的学习过程) 开始时间:2月12日 完成时间:暂未完成 2月18日——系统主窗体设计 只看了学习视频 2月19日—— 回 ...

  3. Unity C# 反射

    什么是反射 在.NET中的反射也可以实现从对象的外部来了解对象(或程序集)内部结构的功能,哪怕你不知道这个对象(或程序集)是个什么东西,另外.NET中的反射还可以运态创建出对象并执行它其中的方法. 反 ...

  4. ElasticSearch安装和核心概念

    1.ElasticSearch安装 elasticsearch的安装超级easy,解压即用(要事先安装好java环境). 到官网 http://www.elasticsearch.org下载最新版的 ...

  5. 设计模式--观察者模式(KVO)

    观察者模式(Observer):观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态上发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 举个例子, ...

  6. Windows8 64位运行Silverlight程序不能访问WCF的解决方案

    公司的项目是Silverlight+WCF,而我的本本是Win8 64位系统,一直无法正常运行Silverlight程序,一个同事找到了方案,现分享出来 一种情况是,Vs2010运行程序时,报无法加载 ...

  7. click事件的累加绑定

    click事件的累加绑定,绑定一次点击事件,执行多次. 在页面中为一个元素绑定事件,事件执行后页面未刷新且元素还在,然后你再次点击,元素又被绑定一个点击事件,这样第二次点击就会执行两次,以此类推. 如 ...

  8. Android商城开发系列(十三)—— 首页热卖商品布局实现

    热卖商品布局效果如下图: 这个布局跟我们上节做的推荐是一样的,也是用LinearLayout和GridView去实现的,新建一个hot_item.xml,代码如下所示: <?xml versio ...

  9. mybatis-动态sql2

    mybatis的动态sql中常用的有    if     where      foreach    set 项目沿用之前的. 1.dao层添加接口: package com.java1234.map ...

  10. innobackupex实现对MySQL的增量备份与还原

    备份增量备份是基于完整备份的,所以我们需要先做一次完整备份: innobackupex --defaults-file=/etc/my.cnf --user root --password cheng ...