Codeforces Round #442 (Div. 2) C - Slava and tanks

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 celln - 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 

题意 有m个水平放置且相邻的格子,每个格子中至少有一个坦克,你需要用导弹消灭这些坦克,如果一个坦克承受伤害的第一时间,瞬间移动到一个相邻细胞(坦克n只能移动到n - 1处,1坦克只能移动到2处)。如果坦克第二次受到伤害,它被计算为毁灭,不再移动。坦克只有在它们第一次被损坏时才会移动,它们不会自行移动。
帮助Slava用几颗炸弹可能摧毁所有的坦克。

在第一行打印M炸弹”需要消灭所有坦克的最小数量。
在第二行打印M的K1,K2 , …,KM。数奇意味着第i个炸弹应该被丢弃在Ki处。


先攻击偶数的格子 然后攻击奇数的格子 再攻击偶数的格子就可以把所有坦克消灭掉了


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	int sum = n & 1 ? n + n / 2 : n + n / 2;
	printf("%d\n", sum);
	for (int i = 1; i <= n; i ++) {
		if (!(i & 1)) printf("%d ", i);
	}
	for (int i = 1; i <= n; i ++) {
		if (i & 1) printf("%d ", i);
	}
	for (int i = 2; i <= n; i ++) {
		if (!(i & 1)) printf("%d ", i);
	}
	printf("\n");
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值