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

Codeforces Round #298 (Div. 2), problem: (A) Exam

时间:2015-05-27 10:19:29      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:cf

A. Exam
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

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 tok?-?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-5 比较奇葩 直接输出就好

其他的比如 6   1 2 3 4 5 6 输出 n 下一行就是依次以递增顺序输出奇数和偶数   1 3 5 2 4 6   7    7   1 3 5 7 2 4 6   其他的同理



 code=======

#include<iostream>
#include<cstdio>
using namespace std;

int a[5000+100];


int main()
{
    int n;
    for(int i=1;i<=5005;i++)
        a[i]=i;

    while(~scanf("%d",&n))
    {
        if(n==1||n==2) printf("1\n1\n");
        else if(n==3) printf("2\n1 3\n");
        else if(n==4) printf("4\n3 1 4 2\n");
        else if(n==5) printf("5\n2 4 1 3 5\n");
        else
        {
            printf("%d\n",n);
            for(int i=1;i<=n;i+=2)
                 printf("%d ",a[i]);
            for(int i=2;i<=n;i+=2)
                if((!(n&1)&&i!=n)||(n&1&&i!=n-1))
                    printf("%d ",a[i]);
                else printf("%d\n",a[i]);
        }
    }
    return 0;
}


Codeforces Round #298 (Div. 2), problem: (A) Exam

标签:cf

原文地址:http://blog.csdn.net/weirdomaybe/article/details/46038313

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