数学算法: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 ...
随机推荐
- oop典型应用:实体类
1. 要知道这个图三者的关系 2.实体类属性类型与数据库类型 3.readonly与const的对比 两者的区别如下: ①const能修饰类中的字段(field)或者局部变量(local variab ...
- 利用Cookie保存用户身份信息实现免登录
<%@page import="sun.misc.BASE64Encoder"%> <%@page import="java.util.Base64.E ...
- Atcoder训练计划
争取三天做完一套吧,太简单的就写一句话题解吧(其实也没多少会做的). 自己做出来的在前面用*标记 agc007 *A - Shik and Stone 暴力dfs即可,直接判断个数 *B - Cons ...
- HTTP响应报文与工作原理详解(转)
超文本传输协议(Hypertext Transfer Protocol,简称HTTP)是应用层协议.HTTP 是一种请求/响应式的协议,即一个客户端与服务器建立连接后,向服务器发送一个请求;服务器接到 ...
- C++中构造函数的写法
class Circle { public: Circle(float r); private: float radius; }; Circle::Circle(float r) { radius = ...
- SpringBoot常用应用属性配置表
#========================================= #COMMON SPRING BOOT PROPERTIES # #This sample file is pro ...
- Excel2Dataset
//获取用户打开的Excel文档路径 private stringkkk() { OpenFileDialog selectFile = new OpenFileDialog(); selectFil ...
- 在eclipse上搭建springBoot
1,具体步骤网上有,需要注意的是,如果是maven项目,需要先下载maven,配置环境变量,再在eclipse-windows -- preference -- maven,选择usersetting ...
- git图形管理工具
在windows下使用git命令行工具对非开发人员还是挺困难的,还好有TortoiseGit这个工具svn客户端用TortoiseSVNgit客户端用TortoiseGit 网址:https://to ...
- UOJ#126【NOI2013】快餐店
[NOI2013]快餐店 链接:http://uoj.ac/problem/126 YY了一个线段树+类旋转卡壳的算法.骗了55分.还比不上$O(n^2)$暴力T^T 题目实际上是要找一条链的两个端点 ...