数学算法:CF534A-Exam(思维)
Exam
time limit per test 1 second
256 megabytes
standard input
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.
A single line contains integer n (1 ≤ n ≤ 5000)
— the number of students at an exam.
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
#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(思维)的更多相关文章
- Scratch编程与高中数学算法初步
scratch编程与高中数学算法初步 一提到编程,大家可能觉得晦涩难懂,没有一定的英语和数学思维基础的人,一大串的编程代码让人望而步,何况是中小学生. Scratch是一款由麻省理工学院(MIT) ...
- 简单数学算法demo和窗口跳转,关闭,弹框
简单数学算法demo和窗口跳转,关闭,弹框demo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...
- HDU 6651 Final Exam (思维)
2019 杭电多校 7 1006 题目链接:HDU 6651 比赛链接:2019 Multi-University Training Contest 7 Problem Description Fin ...
- CF534A Exam 构造
An exam for n students will take place in a long and narrow room, so the students will sit in a line ...
- 数学算法:poweroj1026-丑数(根据固定倍数得到从小到大的序列)
题目: 1026: 丑数 Time Limit: 1000 MS Memory Limit: 65536 KB Total Submit: 257 Accepted: 112 Page View: 1 ...
- 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 ...
- noip201403螺旋矩阵【普及组】数学算法
思路如下: 1.输入n>>a>>b; 2.用一个循环缩小范围求出a,b所示的数所在的圈数q; 3.再一个循环求出圈数q的第1个数的值sum; 4.用四个if判断a,b所示的数在 ...
- [原][c++][数学]osg常用图形数学算法小结
1.cos趋近 // a reasonable approximation of cosine interpolation double smoothStepInterp( double t ) { ...
- codeforces Round #440 C Maximum splitting【数学/素数与合数/思维/贪心】
C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- C# EF 生成1-20随机数,生成10个,不能重复 LINQ写法
, ).Select(x => ).ToList(); foreach (var i in num) { Console.WriteLine(i); } 上面的函数碉堡天了
- NopI 导出数据
protected void exportAward(DataSet dsResult) { if (dsResult != null) { string fileName = System.Web. ...
- jQuery图片组展示插件----Galleria使用简介
1.技术目标 掌握Galleria插件的基本操作 2.Galleria简介 Galleria是一个jQuery插件,可用于展示多张图片,操作也比较简单, 展示效果也非常不错,如图: 提示:Galler ...
- 面试(Java之IO与NIO)
一.概念 NIO即New IO,这个库是在JDK1.4中才引入的.NIO和IO有相同的作用和目的,但实现方式不同,NIO主要用到的是块,所以NIO的效率要比IO高很多.在Java API中提供了两套N ...
- java之struts框架入门教程
本教程主要讲述struts的简单入门操作 使用的是myeclipse工具 1.创建web项目 2.复制struts必要的jar包到 WebRoot/WEB-INF/lib 下 jar包列表如下: as ...
- C++ 强制类型转换(转载)
转载自:http://www.weixueyuan.net/view/6329.html 在C++语言中新增了四个关键字static_cast.const_cast.reinterpret_cast和 ...
- RxJava2 中多种取消订阅 dispose 的方法梳理( 源码分析 )
Github 相关代码: Github地址 一直感觉 RxJava2 的取消订阅有点混乱, 这样也能取消, 那样也能取消, 没能系统起来的感觉就像掉进了盘丝洞, 迷乱… 下面说说这几种情况 几种取消的 ...
- 【Mood-13】Android --如何从初级工程师进化为高级工程师
一 明确自我定位 现在你是初级工程师,但是你想当个高级工程师,所 以,你就要给自己定个目标,即:我是要成为高级工程师的男人.有了这个定位,并且努力朝着这个目标去努力,然后内心深处就会有一个感觉,这个 ...
- 【Android开发笔记】返回上层Activity的正确打开方式
技术支持 http://stackoverflow.com/questions/12276027/how-can-i-return-to-a-parent-activity-correctly 首先, ...
- 在ActionBar中,即便设置showAsAction="always",items仍然在overflow中显示的问题
今天很是苦恼,明明设置了android:showAsAction="always",但是所有的items全部都显示在overflow中,然后在官网发现了答案. 如果你为了兼容 An ...