CF534A Exam 构造
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.
6
6
1 5 3 6 2 4
3
2
1 3 直接特判n<=4
对于n>4,肯定是可以全部出来的
构造:先输出所有奇数,再输出所有偶数
如n=7,则输出:
7
1 3 5 7 2 4 6
#include<cstdio>
#include<iostream> using namespace std; int main()
{
int n;
cin>>n;
if(n== || n==){
cout<<"1\n1"<<endl;
}
else if(n==){
cout<<"2\n1 3"<<endl;
}
else if(n==){
cout<<"4\n2 4 1 3"<<endl;
}
else{
cout<<n<<endl;
for(int i=;i<=n;i+=)
cout<<i<<" ";
for(int i=;i<=n;i+=){
cout<<i;
if(i==n- || i==n)
cout<<endl;
else
cout<<" ";
}
}
return ;
}
CF534A Exam 构造的更多相关文章
- Codeforces Round #298 (Div. 2) A. Exam 构造
A. Exam Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/A Des ...
- MVC 构造新Model实现内容搜索
当前在使用MVC开发一个网站,习惯了使用ASP.NET中控件,转到MVC之后突然对于页面和后台代码的传值感觉无从下手.花了点时间在网上看了写帖子后,想到了一个方法,重新构造一个新Model, 然后利用 ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 构造
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...
- 【Java】-NO.20.Exam.1.Java.1.001- 【1z0-807】- OCEA
1.0.0 Summary Tittle:[Java]-NO.20.Exam.1.Java.1.001-[1z0-807] Style:EBook Series:Java Since:2017-10- ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
- Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforces1016 D. Vasya And The Matrix(思维+神奇构造)
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Vasya And The Matrix CodeForces - 1016D (思维+构造)
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the ma ...
- 学习笔记:Maven构造版本号的方法解决浏览器缓存问题
需要解决的问题 在做WEB系统开发时,为了提高性能会利用浏览器的缓存功能,其实即使不显式的申明缓存,现代的浏览器都会对静态文件(js.css.图片之类)缓存.但也正因为这个问题导致一个问题,就是资源的 ...
随机推荐
- PMP-合同类型
1.Fixed-price or lump-sum contracts(固定总价或总包合同)简称FP 这是买方(甲方)最能受益的合同类型.不管乙方开销多大,甲方付的钱是固定不变的. 2.Time an ...
- [POI 2008][BZOJ 1132]Tro
这题我真是无能为力了 这题的做法还是挺简单的 枚举左下角的点做为原点,把其余点按极角排序 PS.是作为原点,如枚举到 k 时,对于所有 p[i] (包括p[k]) p[i]-=p[k] (此处为 ...
- 如何在WTL和MFC中使用duilib及如何静态使用duilib库!(初级讲解 附带一个Demo)
关于duilib的历史,我也就不多说了,能看到这篇文章的人都是有一定了解才能找到这个的. 我直接说下对这个库的基本使用吧. 我个人对一些好技术都是比较感兴趣的. 因为个人原因 喜欢接触一个好技术. 所 ...
- sql commands
1,DBCC SQLPERF(logspace) https://msdn.microsoft.com/en-us/library/ms189768.aspx 2, 1, LOGINFO(''HAHA ...
- int(M)与int
int(M) ,加上zerofill后M才表现出有点效果,比如 int(3) zerofill,你插入到数据库里的是10,则实际插入为010,也就是在前面补充加了一个0.如果int(3)和int(10 ...
- httplib
可爆破目录 import httplib import urllib def sendhttp(): data = urllib.urlencode({'@number': 12524, '@type ...
- ctf之加密
from:http://drops.wooyun.org/tips/10002 0x01 Base64 Base64:ZXZhbCgkX1BPU1RbcDRuOV96MV96aDNuOV9qMXVfU ...
- linux框架之ibus
框架与具体输入法安装 ibus是一个框架,安装好ibus框架后,只需要安装ibus平台下具体的输入法即可,海风或极点五笔,然后注销当前账户,重新登录,便可添加新安装的输入法 [root@localho ...
- linux包之iproute之ss命令
概述 [root@localhost ~]# rpm -qa|grep iprouteiproute-2.6.32-31.el6.x86_64 当服务器的socket连接数量变得非常大时,无论是使用n ...
- each和$(this)配合循环_siblings选取同级不同类型元素
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...