码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces534A:Exam

时间:2015-04-18 20:39:11      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:cf

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;
}


Codeforces534A:Exam

标签:cf

原文地址:http://blog.csdn.net/libin56842/article/details/45115887

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!