• CodeForces 877C (Slava and tanks )


    题目链接 CodeForces 877C

                           

                         Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

                                                                                CodeForces 877C

    Description

    Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.

    Formally, map is a checkered field of size 1 × n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.

    If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell n can only move to the cell n - 1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.

    Help Slava to destroy all tanks using as few bombs as possible.

    Input

    The first line contains a single integer n (2 ≤ n ≤ 100 000) — the size of the map.

    Output

    In the first line print m — the minimum number of bombs Slava needs to destroy all tanks.

    In the second line print m integers k1, k2, ..., km. The number ki means that the i-th bomb should be dropped at the cell ki.

    If there are multiple answers, you can print any of them.

    Sample Input

    Input

    2
    

    Output

    3
    2 1 2 

    Input

    3
    

    Output

    4
    2 1 3 2 

    思路:先炸偶数位,在炸奇数位,最后再炸偶数位。

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<map>
    #include<queue>
    #include<stack>
    #include<cstring>
    #include<vector>
    using namespace std;
    typedef long long LL;
    const int MAXN=2e5+10;
    int main()
    {
        LL n,i,j;
        scanf("%lld",&n);
        cout<<n+n/2<<endl;
        for(i=1;i<=n;i++)
            if(i%2==0)
            cout<<i<<" ";
         for(i=1;i<=n;i++)
            if(i%2!=0)
            cout<<i<<" ";
         for(i=1;i<=n;i++)
            if(i%2==0)
            cout<<i<<" ";
        return 0;
    }
  • 相关阅读:
    我就这么点时间,我该做些什么?
    如何排解压力
    渡过难关
    获得财富前,先问一下自己创造了什么
    程序员娶妻之道
    20150929雨
    我是小号
    tensorflow 源码编译tensorflow 1.1.0到 tensorflow 2.0,ver:1.1.0rc1、1.4.0rc1、1.14.0-rc1、2.0.0b1
    python大文件读取
    1《数学之美》第3章 统计语言模型
  • 原文地址:https://www.cnblogs.com/jk17211764/p/9677360.html
Copyright © 2020-2023  润新知