Codeforces 534 A. Exam

题目链接:http://codeforces.com/contest/534/problem/A
题意大意:给出n个学生,编号为1~n,要求学生坐在一排并且相邻的学生编号相差不能为1,求出满足这样要求的最大学生数量并输出方案。
解题思路:除了1,2,3,4以外,其他的都要按照先找奇数,在排偶数。或者先排偶数,再排奇数。

#include <iostream>
using namespace std;
int main()
{
    int m;
    cin>>m;
    if(m == 1)
    {
        cout<<1<<endl;
        cout<<1<<endl;
        return 0;
    }
    if(m == 2)
    {
        cout<<1<<endl;
        cout<<1<<endl;//2也可以
        return 0;
    }
    if(m == 3)
    {
        cout<<2<<endl;
        cout<<1<<" "<<3<<endl;
        return 0;
    }
    if(m == 4)
    {
        cout<<4<<endl;
        cout<<2<<" "<<4<<" "<<1<<" "<<3<<endl;
       return 0;
    }
    cout<<m<<endl;
    cout<<1;
    for(int i=3; i<=m; i+=2)
        cout<<" "<<i;
    for(int i=2; i<=m; i+=2)
        cout<<" "<<i;
    cout<<endl;
    return 0;
}
/*
input
6
output
6
1 5 3 6 2 4
input
3
output
2
1 3
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值