codeforces877C(div2)Slava and tanks(脑洞)
来源:互联网 发布:linux项目实战简历 编辑:程序博客网 时间:2024/06/02 05:16
题目:
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
题意:在一个1*n的地图上每个格子里有若干坦克,当一个坦克被炸一次是他会向两边中的任意一边移动一格,第二次被炸时消失,你每次可以选一个格子轰炸,现在要轰炸次数最少,求最优方案。
对自己的智商深深的无奈。。
策略:先炸所有偶数,再炸奇数,再炸偶数。(为什么是这样?因为奇数个数>=偶数,所以优先炸偶数)。
附上代码:
#include<bits/stdc++.h>using namespace std;int n;int main(){ scanf("%d", &n); printf("%d\n", n / 2 * 3 + 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;}
- codeforces877C(div2)Slava and tanks(脑洞)
- Codeforces 877 C Slava and tanks
- Codeforces 877(442 Div.2) C. Slava and tanks
- Codeforces Round #442 (Div. 2) C. Slava and tanks
- #442 Div.2 AB &C. Slava and tanks 思维题
- Codeforces Round #442 (Div. 2) C. Slava and tanks 【找规律】
- SGU - 316 - Code Tanks (简单模拟)
- B. Kefa and company(#321 div2)
- Codeforces Round #263(div2)C. Appleman and Toastman
- Codeforces Round #264 (div2)B. Caisa and Pylons
- E. Paths and Trees (CF 303 div2)最短路
- codeforces 311(div2)C-Arthur and Table
- Codeforces - 337B(div2) - Vika and Squares(练习)
- Codeforces #669 Div2 C. Little Artem and Matrix(模拟)
- Codeforces #669 Div2. D. Little Artem and Dance(思维)
- Codeforces #325 Div2 D Phillip and Trains(模拟)
- Codeforces #324 Div2 B.Kolya and Tanya(dp、思维)
- Codeforces #324 Div2 C Marina and Vasya(构造)
- Asp.net管道模型(管线模型)
- ansroid studio dependencies problem
- Windows Azure Storage
- 卷积神经网络工作原理直观的解释
- 效率类App原型制作分享-One List
- codeforces877C(div2)Slava and tanks(脑洞)
- 如何利用页面点击图做网站页面优化
- CakePHP beforeFilter
- 类的继承、多态实验-小作业
- 阿里云免费教你使用营销引擎
- ultraedit正则表达式查询
- mytest
- 算法-3Sum问题
- 2017-10-24