zoukankan      html  css  js  c++  java
  • CodeForces

    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
    2
    Output
    3
    2 1 2
    Input
    3
    Output
    4
    2 1 3 2


    在一个1*N的格子里很多坦克,你从高空不知道哪些格子里有坦克,但仍然需要扔炸弹把坦克全都炸毁,坦克第一次被炸到后,一定会向前或者向后移一个格子(第一个格子里的坦克只会向后移一个格子,
    最后一个格子里的坦克只会向前移一个格子),当坦克被第二次炸到的时候才会被炸毁,问你怎样炸,才能使耗费的炸弹最少。

    不要一看到这种题就感到无从下手,它肯定是有规律的。

    在偶数区间里的坦克移动一次后就都到了奇数区间里,奇数区间里的坦克移动一次后就又到了偶数区间里,于是一个大胆的想法就产生了,先偶数区间炸一遍,再奇数区间炸一遍,最后再偶数区间炸一遍。经验正后,可行。

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<string>
     5 #include<cmath>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<stack>
     9 #include<deque>
    10 #include<map>
    11 #include<iostream>
    12 using namespace std;
    13 typedef long long  LL;
    14 const double pi=acos(-1.0);
    15 const double e=exp(1);
    16 const int N = 10;
    17 
    18 int main()
    19 {
    20     LL i,p,j,n;
    21     LL ans=0,x,y;
    22     scanf("%lld",&n);
    23     while(1)
    24     {
    25         ans=n;
    26         for(i=2; i<=n; i+=2)
    27         {
    28             //if(i!=n)
    29                 ans++;
    30         }
    31         printf("%lld
    ",ans);
    32         if(n>=2)
    33             printf("2");
    34         for(i=4; i<=n; i+=2)
    35             printf(" %lld",i);
    36         for(i=1; i<=n; i+=2)
    37             printf(" %lld",i);
    38         for(i=2; i<=n; i+=2)
    39         {
    40 
    41             printf(" %lld",i);
    42         }
    43         putchar('
    ');
    44         break;
    45     }
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    php 字符串查找
    php缓存与加速分析与汇总
    oracle 时间问题
    mysql数据迁移
    浅谈千万级PV/IP规模高性能高并发网站架构
    对memcache分布式的一点理解
    美国程序员将工作廉价外包给中国公司遭解雇
    16个Linux服务器监控命令
    在yii中使用memcache
    Windows电脑快捷健大全
  • 原文地址:https://www.cnblogs.com/daybreaking/p/9694823.html
Copyright © 2011-2022 走看看