CodeForces
来源:互联网 发布:linux mint启动eclipse 编辑:程序博客网 时间:2024/06/06 20:33
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.
The first line contains a single integer n (2 ≤ n ≤ 100 000) — 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 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.
2
32 1 2
3
42 1 3 2
题意: 输入一个数n,n代表有n个位置,每个位置可能有坦克,可能也没有坦克,一个坦克要炸两次才能毁掉,若这个位置有坦克,在这个位置炸一下,这个位置的坦克就会跑到左右相邻的其中一个位置,要把所有坦克都炸毁,求最小的轰炸数;
思路:因为在这个位置炸一下,这个位置的坦克就会跑到左右相邻的其中一个位置,你不知道会跑左边还是右边,所以你就分奇偶,炸奇数的坦克一定会跑偶数里去,炸偶数的坦克一定会跑奇数里去,所以分奇偶数炸,那么是先炸奇数呢,还是先炸偶数呢?先炸偶数,因为给出一个数n,在从1~n的整数中,偶数的数量一定会小于等于奇数的数量,
所以先炸奇数,再炸偶数,再炸奇数;
代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){int i,j,n;while(~scanf("%d",&n)){printf("%d\n",n+n/2);if(n==1){printf("1 1\n");continue;}printf("2");for(i=4;i<=n;i+=2)printf(" %d",i);for(i=1;i<=n;i+=2)printf(" %d",i);for(i=2;i<=n;i+=2)printf(" %d",i);printf("\n");}return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Error occurred during initialization of VM
- CString、string、string.h的区别
- Angular4关于组件与组件之间的通信
- StringBuffer常用方法
- java 矩阵相乘,矩阵线性运算
- CodeForces
- 简单的Fragment切换,Fragment嵌套Viewpager
- 在IntelliJ IDEA建立Servlet
- C++ 多态知识点综合整理
- 人生的84000可能-触动心弦
- oracle:数据库查询返回结果集的默认值
- bzoj 4993(类LCS)
- 区间DP tyvj 1466 最美妙的矩阵
- 4nodejs 的简介与安装