数学算法: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 ...
随机推荐
- Kotlin lateinit 和 by lazy 的区别
1.lazy{} 只能用在val类型, lateinit 只能用在var类型 2.lateinit不能用在可空的属性上和java的基本类型上 3.lateinit可以在任何位置初始化并且可以初始化多次 ...
- Ionic2集成DevExtreme
安装Install DevExtreme Angular npm install --save devextreme devextreme-angular 或者在package.json 文件中增加依 ...
- X64下IIS调用32位的dll
WebAPI项目中遇到了需要调用32位C++的dll的情况,调试的时候能正常调用,但是发布了之后部署在IIS中出现了BadFormatImage异常, 解决方法是在IIS中相应应用程序池=>高级 ...
- wepy-cli 开发小程序如何使用vant组件
同样使用wepy-cli快速生成的小程序,目前可以使用组件: 直接通过 git 下载 Vant Weapp 源代码,并将dist目录拷贝到自己的项目中 git clone https://github ...
- 《C++面向对象程序设计》之变量的生存期
<C++面向对象程序设计>之变量的生存期 静态生存期 (1)全局静态生存期:在函数体外声明,作用域从声明处开始到文件结尾处结束,称其有文件作用域,相当于全局变量 . (2)局部静态生存期: ...
- Cocos2d-x v3.1 坐标系统(五)
Cocos2d-x v3.1 坐标系统(五) 为了能够更好的布局以及了解对象所在的位置,我们必须对Cocos2d-x中的坐标有详细的了解,本篇文章主要就是了解Cocos中用到的坐标系统.学过数学的人都 ...
- python any all函数
a = [0, 0, 0, 0] b = [0, 0, 0, 1] c = [1, 1, 1, 1] >>> any(a) False >>> any(b) Tru ...
- jQuery_2_常规选择器-简单选择器
JQuery最核心的组成部分就是:选择器引擎.它继承了css的语法,可以对DOM元素的标签名.属性名.状态等进行快速准确的选择. jQuery选择器的写法与CSS 选择器十分类似,只不过他们的功能不同 ...
- LeetCode Valid Anagram (简单题)
题意: 给出两个字符串s和t,判断串t是否为s打乱后的串. 思路: 如果返回的是true,则两个串的长度必定相等,所有字符出现的次数一样.那么可以统计26个字母的次数来解决,复杂度O(n).也可以排序 ...
- COGS 898. [咲 -Saki-] 天才麻将少女什么编
★☆ 输入文件:sakinani.in 输出文件:sakinani.out 简单对比时间限制:1 s 内存限制:256 MB 题目背景 二十一世纪,世界上的麻将竞技人数超过一亿,日本每 ...