codeforces 877C

C. Slava and tanks
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
2
output
3
2 1 2
input
3
output
4
2 1 3 2

(这一题。。能想到会感觉太容易了,像我这种想不到的。。就会不知道从哪入手。。。

解题思路:先炸偶数,这样坦克都会跑到奇数,再炸奇数,奇数上的坦克都会跑到偶数,再炸偶数,就全炸死了。

ac代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int main() {
 5     int n;
 6     scanf("%d",&n);
 7     printf("%d
",n+n/2);
 8     for(int i=2;i<=n;i+=2) {
 9         printf("%d ",i);
10     }
11    // printf("
");
12     for(int i=1;i<=n;i+=2) {
13         printf("%d ",i);
14     }
15   //  printf("
");
16     for(int i=2;i<=n;i+=2) {
17         printf("%d ",i);
18     }
19  //   printf("
");
20     return 0;
21 }
View Code
原文地址:https://www.cnblogs.com/zmin/p/7725142.html