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+1就足够了,但是坦克并不会傻乎乎的超最坏方向走,因此要满足所有的可能性。
最好的办法是先炸偶数,再炸奇数,最后再炸偶数。
#include <algorithm> //STL通用算法
#include <bitset> //STL位集容器
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque> //STL双端队列容器
#include <exception> //异常处理类
#include <fstream>
#include <functional> //STL定义运算函数(代替运算符)
#include <limits>
#include <list> //STL线性列表容器
#include <map> //STL 映射容器
#include <iomanip>
#include <ios> //基本输入/输出支持
#include<iosfwd> //输入/输出系统使用的前置声明
#include <iostream>
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <queue> //STL队列容器
#include <set> //STL 集合容器
#include <sstream> //基于字符串的流
#include <stack> //STL堆栈容器
#include <string> //字符串类
#include <vector> //STL动态数组容器
#define ll long long
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define dep(i,a,b) for(register int i=(a);i>=(b);i--)
//priority_queue<int,vector<int>,less<int> >q;
int dx[]= {-1,1,0,0,-1,-1,1,1};
int dy[]= {0,0,-1,1,-1,1,1,-1};
const int maxn = 5000+66;
const int maxm=100000+66;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
const int INF=99999999;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",n+n/2);
for(int i=2;i<=n;i+=2)
{
printf("%d ",i);
}
for(int i=1;i<=n;i+=2)
{
printf("%d ",i);
}
for(int i=2;i<=n;i+=2)
{
printf("%d ",i);
}
printf("\n");
}
return 0;
}