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

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;
}
时间: 2024-11-25 22:07:46

Codeforces Round #298 (Div. 2), problem: (A) Exam的相关文章

Codeforces Round #298 (Div. 2) A. Exam(水)

题意:N 个学生 编了号,  然后第i个学生不能和第i+1和第i-1坐在一起,问合法的情况下最多坐多少个人,如何做 题解: 水题YY了一下,打表处理前三种    后面的情况就是在第三种情况下往前后插数字   奇数在后  偶数在前,然后没了 代码: #include<stdio.h> #include<string.h> int main() { int n, mymap[5005]; int mark[3][4] = {{1, 1}, {1, 1}, {2, 1, 3}}; whi

Codeforces Round #298 (Div. 2) A、B、C题

题目链接:Codeforces Round #298 (Div. 2) A. 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

Codeforces Round #253 (Div. 2), problem: (B)【字符串匹配】

简易字符串匹配,题意不难 1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 8 int main(){ 9 int i, j, k, t, n; 10 int num, flag, ans; 11 char a[300]; 12 sc

Codeforces Round #466 (Div. 2) Problem A - E

从这里开始 题目列表 小结 Problem A Points on the line Problem B Our Tanya is Crying Out Loud Problem C Phone Numbers Problem D Alena And The Heater Problem E Cashback Problem F Machine Learning (Lazy Tag) 小结 这场比赛和同学一起打.本来应该是很开心的事情,结果留下好多遗憾. 第一个遗憾是没能在20分钟内消灭A.B题

Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c). Over time the stars twinkle. At moment 0 the i-th

Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组

Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to h

Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing

http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开始到倒数第二项,当前的a[i]=(a[i-1],a[i],a[i+1])三项排序后的中间项,比如连续3项为 1 0 1,那么中间的就变为1,然后题目让你输出达到稳定状态时所需的最小步数,不能的话输出-1. 无论给你啥数列,都能达到稳态.所以不可能输出-1: 还有一开始就稳定不变,或经过几次变换而稳定

Codeforces Round #425 (Div. 2) Problem C (Codeforces 832C) Strange Radiation - 二分答案 - 数论

n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n

Codeforces Round #226 (Div. 2):Problem 385C - Bear and Prime Numbers (素数刷法+前缀和)

Time Limit: 2000ms Memory Limit: 524288KB This problem will be judged on CodeForces. Original ID: 385C 64-bit integer IO format: %I64d      Java class name: (Any) Prev Submit Status Statistics Discuss Next Type: None Recently, the bear started studyi