A11168 | Slava and tanks
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains a single integer $n$ ( $2<=n<=100000$ ) — the size of the map.
输出格式
In the first line print $m$ — the minimum number of bombs Slava needs to destroy all tanks.
In the second line print $m$ integers $k_{1},k_{2},...,k_{m}$ . The number $k_{i}$ means that the $i$ -th bomb should be dropped at the cell $k_{i}$ .
If there are multiple answers, you can print any of them.
In the second line print $m$ integers $k_{1},k_{2},...,k_{m}$ . The number $k_{i}$ means that the $i$ -th bomb should be dropped at the cell $k_{i}$ .
If there are multiple answers, you can print any of them.
输入输出样例
输入 #1
2
输出 #1
3 2 1 2
输入 #2
3
输出 #2
4 2 1 3 2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted