Codeforces534A:Exam
来源:互联网 发布:回文c语言 编辑:程序博客网 时间:2024/05/23 12:34
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
61 5 3 6 2 4
3
21 3
对1~n的n个数进行排序,输出一个序列使得所有相邻的数差值不为1
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <algorithm>using namespace std;#define ls 2*i#define rs 2*i+1#define up(i,x,y) for(i=x;i<=y;i++)#define down(i,x,y) for(i=x;i>=y;i--)#define mem(a,x) memset(a,x,sizeof(a))#define w(a) while(a)#define LL long longconst double pi = acos(-1.0);#define Len 63#define mod 19999997const int INF = 0x3f3f3f3f;int main(){ int n,i,j,k,a[5005]; w(~scanf("%d",&n)) { if(n==1) { printf("1\n1\n"); continue; } if(n == 2) { printf("1\n1\n"); continue; } if(n == 3) { printf("2\n1 3\n"); continue; } if(n == 4) { printf("4\n2 4 1 3\n"); continue; } int l = 1,r = (n%2)?((n+1)/2+1):(n/2+1); printf("%d\n1",n); l++; up(i,2,n) { if(i%2) { printf(" %d",l); l++; } else { printf(" %d",r); r++; } } printf("\n"); } return 0;}
- Codeforces534A:Exam
- exam
- Exam
- JAVA EXAM
- Pass4Sure exam
- flex exam
- Happy exam
- youdao exam
- EXAM WAS
- CFA Exam
- hdu4473 Exam
- final exam
- codeforces Exam
- A. Exam
- cf.Exam
- A. Exam
- SGU172:eXam
- hdu5240 Exam
- 隐藏压缩文件于图片中(简单的文件合并)
- spring 的Spel
- 【学习笔记10】基本数据结构(栈 队列 链表 有根树)
- 黑马程序员—static关键字—知识点总结
- Heap,创建进程私有堆
- Codeforces534A:Exam
- (1.4.8.3)腾讯2013校园招聘
- Android---20---CheckBox复选框
- Virtual Memory Function Demo
- Android的API Demos
- 从零开始启动一个项目,需要哪些准备工作
- 华为在线测试题[基础篇]--求最小公倍数
- MapFileView示例
- 用Hexo写博客 - ERROR Local hexo not found in xxx