Codeforces534A: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.

Input

A single line contains integer n (1?≤?n?≤?5000) —
the number of students at an exam.

Output

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

6
1 5 3 6 2 4

input

3

output

2
1 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 long
const double pi = acos(-1.0);
#define Len 63
#define mod 19999997
const 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;
}

时间: 2024-10-12 18:33:01

Codeforces534A:Exam的相关文章

UVA 11637 - Garbage Remembering Exam(组合概率)

UVA 11637 - Garbage Remembering Exam 题目链接 题意:大概意思是,有n个单词,分别打乱放在一个环形的,一个非环形里面,环形的两个单词距离为顺时针逆时针的最小值,非环形的就是位置的差的绝对值,如果有一对单词,在两个里面的距离都是不大于k,那么这单词为无效单词,问平均会出现多少个无效单词 思路:组合概率,假设在非环形形成了一个随机序列,那么我们给它标号1-n,如果我们能分别算出1-n的有效概率,那么就等于算出了无效概率,那么有效概率等于和它距离大于k的那些位置的所

【OCM】Exam Souvenir 20140707

[OCM考场合影留念] 经过两天的奋战,又一波恩墨OCM战队的顶尖高手们,凭借百分百的发挥完美收官,到此画上了完美的句号. 传承了霸气的手势!Well done! [请访问此 http://www.dbstyle.net/?p=979页面获得更加丰富的内容] [OCM]Exam Souvenir 20140707,布布扣,bubuko.com

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

HDU5240——贪心——Exam

Problem Description As this term is going to end, DRD needs to prepare for his final exams. DRD has n exams. They are all hard, but their difficulties are different. DRD will spend at least ri hours on the i-th course before its exam starts, or he wi

uva 11637 - Garbage Remembering Exam(概率)

题目链接:uva 11637 - Garbage Remembering Exam 题目大意:大白数里有很详细的题意. 解题思路:对于有序的序列来说,考虑每个位置为有效性的概率.C(2?kn?1?x)?A(2k2k)?A(n?1?xn?1?x)A(n?1n?1) x为考虑当前位置,然后与该位置距离小于等于k的位置个数.该位置有效的话,则对应的要将原先邻近的2*k个单词放到另外的位置上. #include <cstdio> #include <cstring> #include &l

Final Exam Arrangement

题目链接 题意: 输入n个左闭右开的线段,如果两个线段有重叠部分,那么这两个线段必然不能在一组.求,最少分几组,并且输出每组都有谁 分析: 将一个线段拆开成左右端点,排序.从左向右扫描,如果遇到的是左端点,那么直接加入到集合中,此时集合中的这些线段两两有重合部分,所以是可以分到同一组的:如果遇到的是右端点,那么当前线段之后将和当前线段没有重合点,必然不能放到一组.这样贪心的将每一个线段尽可能的分到一个组中(分到哪个组无所谓,只要分到了一个组中,答案就能减少),就可以保证答案是最少的.当一个线段不

Winter &#39;15 Release Exam (dev - 401)

1 of 5. What is a capability of Advanced Setup Search? Choose 2 answers A. Enter search criteria using wildcard characters, such as an asterisk (*). B. Search for individual Setup items, such as workflow rules, by name. C. See which object an item is

有感PMI Exam Dev Workshop

有幸參加了PMI协会在上海举办的PMI Exam Development Workshop活动.这是PMI协会第二次在中国举办此活动,上一次是2009年北京. 我第一次參加,感觉收获非常多. 我们知道,PMI考试题库中的考题一直在不断地完好中,这就须要不断地淘汰旧题目,引入新题目,这次活动的目的就是补充新考题.整个活动分2个主题:评审已存在的题目和加入新的题目. 第一天下午主要是PMI协会的一些大佬演讲. 第二天工作内容是评审以往的考题.部分考题来自题库中不计入考试分数的题目,部分来自其它PMI

Round #425 B. Petya and Exam

It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consis