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. spring技术小结

    1.DI和IOC 依赖注入(Dependency Injection)还是控制反转(Inversion of Conctrol) bean通过依赖注入,注册到spring容器里面.spring容器通过 ...

  2. MS Chart 折线图——去除时间中的时、分、秒,按天统计【转】

    MS Chart 折线图——去除时间中的时.分.秒,按天统计   private void Form2_Load(object sender, EventArgs e){            str ...

  3. swift第一课快速体验playground

    最近听说苹果要大力推行swift语言,所以我必须要赶快好好学一学,今天做第一个就遇到问题. 在Xcode7.2欢迎界面,选中创建第一个,我们一般都是默认创建第二个. 创建完后,出现问题了,提示如下: ...

  4. MPAndroidChart开源图表库---折线图

    项目地址:点击打开,原文参考地址:点击打开 1. 将mpandroidchartlibrary-2-0-8.jar包copy到项目的libs中 2. 定义xml文件 <?xml version= ...

  5. 【干货】Html与CSS入门学习笔记4-8

    四.web镇之旅,连接起来 找一家托管公司如阿里云,购买域名和空间,然后将网页文件上传到购买的空间的根目录下. 1.绝对路径url url:uniform resource locators 统一资源 ...

  6. 配置Ubuntu DNS

    首先,你可以在/etc/hosts中加入一些主机名称和这些主机名称对应的IP地址,这是简单使用本机的静态查询.要访问Ubuntu DNS 服务器来进行查询,需要设置/etc/resolv.conf文件 ...

  7. js对jsonArray的操作

    上一篇写了关于java中Gson对jsonArray的排序处理,这里介绍js中对jsonArray处理, <!DOCTYPE html> <html> <head> ...

  8. meterpreter > run post/windows/capture/keylog_recorder

    meterpreter > migrate 1548[*] Migrating to 1548...[*] Migration completed successfully.meterprete ...

  9. 禁止ASP.NET MVC模型绑定时将空字符串绑定为null

    为model添加[DisplayFormat(ConvertEmptyStringToNull = false)] [Display(ResourceType = typeof(AppStrings) ...

  10. 让SAP云平台上的Web应用使用destination服务

    首先在SAP云平台里创建一个destination,维护service的end point: 然后打开SAP云平台的WebIDE,创建一个新的文件夹和新的HTML5 Application Descr ...