CF Exam (数学)
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 tok - 1.
If there are several possible answers, output any of them.
6
6
1 5 3 6 2 4
3
2
1 3
只有前三个情况特殊,后面都是N,特判一下,先输出偶数再输出奇数。
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using namespace std; int main(void)
{
int n,i; while(cin >> n)
{
if(n == || n == )
cout << "" << endl << "" << endl;
else if(n == )
cout << "" << endl << "1 3" << endl;
else
{
cout << n << endl;
for(i = ;i <= n;i += )
cout << i << ' ';
for(i = ;i <= n;i += )
if(i + > n)
cout << i;
else
cout << i << ' ';
cout << endl;
}
} return ;
}
CF Exam (数学)的更多相关文章
- hdu 4473 Exam 数学
思路: 将条件转化为满足abc<=n的abc的数目. 1.3个数相等时,为 A; 2.有2个数相等时,为 B; 3.都不相等时,为 C. 则结果为A+3*B+6*C. 代码如下: #includ ...
- CF Spreadsheets (数学)
Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input ...
- linux文件管理之解压缩
文件的压缩与解压缩 Linux文件压缩工具有:gzip.bzip2.rar.7zip.lbzip2.xz.lrzip.PeaZip.arj等.============================= ...
- 第18章-x86指令集之常用指令
x86的指令集可分为以下4种: 通用指令 x87 FPU指令,浮点数运算的指令 SIMD指令,就是SSE指令 系统指令,写OS内核时使用的特殊指令 下面介绍一些通用的指令.指令由标识命令种类的助记符( ...
- 【JVM源码解析】模板解释器解释执行Java字节码指令(上)
本文由HeapDump性能社区首席讲师鸠摩(马智)授权整理发布 第17章-x86-64寄存器 不同的CPU都能够解释的机器语言的体系称为指令集架构(ISA,Instruction Set Archit ...
- CF 990A. Commentary Boxes【数学/模拟】
[链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...
- CF #305(Div.2) D. Mike and Feet(数学推导)
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- cf.295.C.DNA Alignment(数学推导)
DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- CF Amr and Pins (数学)
Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
随机推荐
- 内核参数优化/etc/sysctl.conf
net.nf_conntrack_max = 65536000net.netfilter.nf_conntrack_tcp_timeout_established = 1200net.ipv4.tcp ...
- homework6-更加简单的题目
又把时间搞错了 以为这次要写客户端程序的博客 没想到这次是“怎么吃” 言归正传 cnblog上面有很多技术博客 http://perhaps.cnblogs.com/archive/2005/08/0 ...
- build.gradle 使用tips
7.查看依赖 gradlew [你想查看的module]:dependencies >dependencies.txt 6.buildToolsVersion build tools版本号 co ...
- 分享iOS最喜欢的技巧和提示
转自:http://blog.csdn.net/biggercoffee/article/details/50394027 Objective-C 1.让Xcode的控制台支持LLDB类型的打印 这有 ...
- HDU 1875 畅通工程再续 (最小生成树)
畅通工程再续 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/M Description 相信大家都听说一个"百岛湖&q ...
- POJ 1611 The Suspects (并查集)
The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...
- Spring EL Lists, Maps example
In this article, we show you how to use Spring EL to get value from Map and List. Actually, the way ...
- nyoj 203 三国志(最短路加01背包)
三国志 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 <三国志>是一款很经典的经营策略类游戏.我们的小白同学是这款游戏的忠实玩家.现在他把游戏简化一下, ...
- BPL插件框架的二种实现
1)非RTTI方式适用于所有的DELPHI版本 unit untMain; interface uses Windows, Messages, SysUtils, Classes, Graphics, ...
- CodeForces 707C Pythagorean Triples (数论)
题意:给定一个数n,问你其他两边,能够组成直角三角形. 析:这是一个数论题. 如果 n 是奇数,那么那两边就是 (n*n-1)/2 和 (n*n+1)/2. 如果 n 是偶数,那么那两边就是 (n/2 ...