第五次个人赛
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
题意:炸坦克,一个坦克两条命, 输入一个数n,n代表有n个位置,每个位置可能有坦克,可能也没有坦克,一个坦克要炸两次才能毁掉,若这个位置有坦克,在这个位置炸一下,这个位置的坦克就会跑到左右相邻的其中一个位置,要把所有坦克都炸毁,求最小的轰炸数;
其他大神分析:我们可以先对偶数位的格子投放炸弹,此时被炸的坦克一定会移向奇数位的格子,之后对奇数位的格子投放炸弹,之前移过来的坦克已损毁,但初始位于奇数位的坦克会移向偶数位的格子,我们再对偶数位的格子投放炸弹。这时所有坦克无论在哪都必定损毁。
思路:题目给了1~n的格子,格子的偶数一定小于等于奇数,例如5,奇数1,3,5,偶数2,4;例如4,奇数2,4,偶数1,3,那么我们可以以5个格子进行分析,我们为什么不炸奇偶奇,而选择偶奇偶,炸奇偶奇有3+2+3次,炸偶奇偶有2+3+2次,题中要求最小的轰炸数,所以我们选择偶奇偶
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
typedef long long LL;
int main()
{
int n,i;
scanf("%d",&n);
printf("%d\n",n+n/2);
for(i=2; n>=i; i=i+2)
{
printf("%d ",i);
}
for(i=1; n>=i; i=i+2)
{
printf("%d ",i);
}
for(i=2; n>=i; i=i+2)
{
printf("%d ",i);
}
return 0;
}