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. Java排序算法(一)

    Java排序算法(一) 排序的基本概念和分类 1.1排序的定义 在<大话数据结构>中,排序定义为,假设含有n个记录的序列为{r1,r2,...,rn},其相应的关键字{k1,k2,..., ...

  2. 《C#高效编程》读书笔记09-避免在API中使用转换操作符

    转换操作符为类之间引入了一种"可替换性"(substitutability)."可替换性"表示一个类的实例可以替换为另一个类的实例. public class ...

  3. 如何配置阿里Maven镜像

    1.下载maven的zip解压,官方下载地址为:http://maven.apache.org/download.cgi 选择需要下载maven的版本就好了 2.到下载的maven路径下,conf/s ...

  4. metaclass元类解析

    一.创建类的流程 二.什么是元类 在Python3中继承type的就是元类 示例 # 方式一 class MyType(type): '''继承type的就是元类''' def __init__(se ...

  5. Javascript Functions

    Javascript 全局对象 全局属性和函数可用于所有内建的Javascript对象 顶层函数(全局函数) decodeURI()解码某个编码的URI. decodeURIComponent()解码 ...

  6. linux 下源码编译环境配置

    yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel \ fontconfig fo ...

  7. thinkphp分页+条件查询

    最近项目上面有一个带条件查询的分页列表,一开始form用的post,点击第二页就没有跳转成功,原因是分页是get请求,post数据链接到其他页面就会被清除. 解决办法: 1.form表单method= ...

  8. pyinstaller打包python源程序访问hive

    1.需求 使用hvie server一段时间后,业务部门需要自己不定时的查询业务数据,之前这一块都是他们提需求我们来做,后来发现这样重复一样的工作放在我们这边做是在没有效率,遂提出给他们工具或者web ...

  9. 用户在设置密码时,提醒请输入半角字符(vue+element+valid)

    要保证callback()只有一个出口 rules:{ newPassword: [{validator:(rule,newPassword,callback)=>{ var all = fal ...

  10. IOS Quartz2D自定义view

    @property (nonatomic, weak) UIImageView *imageView; @property (nonatomic, weak) NJImageView *njIv; @ ...