Codeforces 877 C. Slava and tanks
2 seconds
256 megabytes
standard input
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.
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
3
2 1 2
3
4
2 1 3 2 题意:
n列格子上有inf辆坦克
每辆坦克两滴血
向第i列扔炸弹,第i列的坦克会移动到i-1和i+1列,减一滴血
问最少扔多少炸弹,炸毁所有坦克 先往偶数格打,所有坦克跑到奇数格
再往奇数格打,所有坦克跑到偶数格
再往偶数格打,所有坦克打死
#include<cstdio> using namespace std; int n; int main()
{
scanf("%d",&n);
printf("%d\n",n+n/);
for(int i=;i<=n;i+=) printf("%d ",i);
for(int i=;i<=n;i+=) printf("%d ",i);
for(int i=;i<=n;i+=) printf("%d ",i);
}
Codeforces 877 C. Slava and tanks的更多相关文章
- Slava and tanks 877C
C. Slava and tanks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 414D Mashmokh and Water Tanks
codeforces 414D Mashmokh and Water Tanks 题意 题解 \(a_i\):第 \(i\) 层的结点个数. \(b_i\):第 \(i\) 层初始有水的结点个数. 如 ...
- Codeforces 877C Slava and tanks(思维)
题目链接:http://codeforces.com/problemset 题目大意:有n个格子,某些格子里可能有一个或多个坦克,但不知道具体位置,每个坦克被轰炸一次就会移动到相邻的格子里(第1个格子 ...
- 【Codeforces Round #442 (Div. 2) C】Slava and tanks
[链接] 我是链接,点我呀:) [题意] 有n个位置,每个位置都可能有不定数量的tank; 你每次可以选择一个位置投掷炸弹. 并且,这个位置上的所有tank都会受到你的攻击. 并且失去一点体力. 然后 ...
- Codeforces 877 D. Olya and Energy Drinks
http://codeforces.com/contest/877/problem/D D. Olya and Energy Drinks time limit per test 2 second ...
- codeforces 877 E. Danil and a Part-time Job(线段树(dfs序))
题目链接:http://codeforces.com/contest/877/problem/E 题解:显然一看就感觉要么树链剖分要么线段树+dfs序,题目要求的操作显然用线段树+dfs序就可以实现. ...
- 887C. Slava and tanks#轰炸弹坦克游戏(分析)
题目出处:http://codeforces.com/problemset/problem/877/C 题目大意:按照游戏规则,求最小炸弹使用次数 #include<iostream> u ...
- 【codeforces 175D】 Plane of Tanks: Duel
http://codeforces.com/problemset/problem/175/D (题目链接) 题意 A,B两人玩坦克大战,坦克有生命值,射击间隔,伤害范围,未命中的概率.问A赢的概率是多 ...
- Codeforces Round #442 Div.2 A B C D E
A. Alex and broken contest 题意 判断一个字符串内出现五个给定的子串多少次. Code #include <bits/stdc++.h> char s[110]; ...
随机推荐
- MAVEN ERROR maven-resources-plugin
maven新建项目时报错 Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin: ...
- json反序列化对象
这个是同事研究的wcf中中根据type类型反序列化json的示例 /// <summary> /// json转对象 /// </summary> /// <param ...
- PythonWeb 服务部署文档及迁移到Linux相关
pythonWeb的部署(Django+Uwsgi): 1. 部署服务器上需要的Python3.6环境: 安装集成了python3.6 和pip ,virtualenv虚拟环境 的Anaconda(A ...
- Windows Apache(ApacheHaus)安装配置教程
1,Apache下载 选择一个版本,点击Download 点击File For Microsoft Windows 由于Apache HTTP Server官方不提供二进制(可执行)的发行版,所以我们 ...
- mongodb 下载安装 转
MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型.M ...
- [转帖]select提高并发,select和poll、epoll的区别(杂)
同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的上下文下给出的答案是不同的.所以先限定一下本文的上下文. https://www.2cto.com/kf/20161 ...
- [华商韬略] 拉里·埃里森(Larry Elison) 的传奇人生
拉里·埃里森(Larry Elison) 的传奇人生 开战机.玩游艇.盖皇宫,挑战比尔·盖茨,干掉50多家硅谷豪强……全世界比拉里·埃里森更有钱的只有5个,像他这样的硅谷“坏孩子”却是唯一. 19 ...
- Django知识总汇
基础 Django基础 Django基本命令 model系统 ORM基础 ORM字段和参数 ORM对数据库操作 ORM中介模型 ORM之其他骚操作 templates系统 模板语言 views系统 视 ...
- DBGridEH序号的自动生成
序号的自动生成1.定义变量 private maxno:integer; public bmodified:boolean;2.写函数 function max(c ...
- Lottie开源库实现Android动画效果
Lottie简介 Lottie是一个支持Android.iOS.React Native,并由Adobe After Effects制作aep格式的动画,然后经由bodymovin插件转化渲染为jso ...