zoukankan      html  css  js  c++  java
  • Slava and tanks 877C

    C. Slava and tanks
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    Examples
    input
    Copy
    2
    output
    Copy
    3
    2 1 2
    input
    Copy
    3
    output
    Copy
    4
    2 1 3 2
    题意:炸坦克,如果炸第一个坦克,它只能跑到第二个坦克,如果炸第n个坦克,它只能跑到第n-1个坦克,如果炸中间坦克,它可以跑到它相邻的坦克上
    分析:先炸偶数位上的坦克(因为偶数总是比奇数少),然后偶数位上的坦克都跑到奇数位上了,再炸奇数位上的坦克,原来偶数位上的坦克就没了,奇数位上的所有坦克跑到偶数位上去了,然后再炸一次偶数位上的坦克,这下所有的坦克都炸没了
     1 #include<cstdio>
     2 int main()
     3 {
     4     int n;
     5     while(~scanf("%d",&n))
     6     {
     7         printf("%d
    ",3*n/2);//总次数
     8         for(int i=2;i<=n;i+=2)
     9         {
    10             printf("%d ",i);
    11         }
    12         for(int i=1;i<=n;i+=2)
    13         {
    14             printf("%d ",i);
    15         }
    16         for(int i=2;i<=n;i+=2)
    17         {
    18             printf("%d ",i);
    19         }
    20         printf("
    ");
    21     }
    22     return 0;
    23 }
  • 相关阅读:
    [转帖]ExtJs与服务器的交互(一)
    Ext_两种处理服务器端返回值的方式
    命令行调用dubbo远程服务
    【转】Lombok Pojo默认初始值问题
    【转】Python之可变参数,*参数,**参数,以及传入*参数,进行解包
    Python获取并输出当前日期时间
    idea上 实现了Serializable接口,要自动生成serialVersionUID的方法
    mac下python2.x和python3.x的安装方法和升级方法/卸载
    工程代码不编译src的java目录下的xml文件问题及解决
    Spring Aop织入点语法
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/9705797.html
Copyright © 2011-2022 走看看