Slava and tanks 877C
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 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
3
2 1 2
3
4
2 1 3 2
题意:炸坦克,如果炸第一个坦克,它只能跑到第二个坦克,如果炸第n个坦克,它只能跑到第n-1个坦克,如果炸中间坦克,它可以跑到它相邻的坦克上
分析:先炸偶数位上的坦克(因为偶数总是比奇数少),然后偶数位上的坦克都跑到奇数位上了,再炸奇数位上的坦克,原来偶数位上的坦克就没了,奇数位上的所有坦克跑到偶数位上去了,然后再炸一次偶数位上的坦克,这下所有的坦克都炸没了
#include<cstdio>
int main()
{
int n;
while(~scanf("%d",&n))
{
printf("%d\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);
}
printf("\n");
}
return ;
}
Slava and tanks 877C的更多相关文章
- Codeforces 877 C. Slava and tanks
http://codeforces.com/problemset/problem/877/C C. Slava and tanks time limit per test 2 seconds me ...
- Codeforces 877C Slava and tanks(思维)
题目链接:http://codeforces.com/problemset 题目大意:有n个格子,某些格子里可能有一个或多个坦克,但不知道具体位置,每个坦克被轰炸一次就会移动到相邻的格子里(第1个格子 ...
- 【Codeforces Round #442 (Div. 2) C】Slava and tanks
[链接] 我是链接,点我呀:) [题意] 有n个位置,每个位置都可能有不定数量的tank; 你每次可以选择一个位置投掷炸弹. 并且,这个位置上的所有tank都会受到你的攻击. 并且失去一点体力. 然后 ...
- 887C. Slava and tanks#轰炸弹坦克游戏(分析)
题目出处:http://codeforces.com/problemset/problem/877/C 题目大意:按照游戏规则,求最小炸弹使用次数 #include<iostream> u ...
- codeforces877c
C. Slava and tanks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #442 (Div. 2)A,B,C,D,E(STL,dp,贪心,bfs,dfs序+线段树)
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #442 Div.2 A B C D E
A. Alex and broken contest 题意 判断一个字符串内出现五个给定的子串多少次. Code #include <bits/stdc++.h> char s[110]; ...
- CodeForces - 877C
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very speci ...
- Gym 100646 F Tanks a Lot RMQ
Problem F: Tanks a Lot Imagine you have a car with a very large gas tank - large enough to hold what ...
随机推荐
- Zabbix 卸载包 采用yum方式
- MySQL分布式实现ID自增
由于数据量以及IO效率的因素,很多项目对数据支持的数据库会采取分库分表的方式.使用了分库分表之后需要解决的一个问题就是主键的生成.多个表之间的主键就不能用数据库本身的自增主键来支持,因为不同表之间生成 ...
- ES6核心内容讲解
ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015. 也就是说,ES6就是ES2015. ...
- delphi EncdDecd.pas单元中Encoding方法出现#$D#$A的解决方法
例如: s:= 'http://detail.tmall.com/item.htm?id=45545826531&abbucket=_AB-M129_B17&acm=03130.100 ...
- (转)Java调用Weservice
原文地址:http://www.cnblogs.com/jiangxu1989/p/6491483.html https://www.cnblogs.com/neughj/p/5145630.html ...
- c语言数据类型(一)
(强数据类型) 1.常量 常量是程序中不可变的量 10为常量 两种常量 #define 定义宏常量 const #对于#define 类型的常量,c语言的习惯是常量名称大写, 对于普通const常量以 ...
- Distributed traceability with Spring Cloud: Sleuth and Zipkin
I. Sleuth 0. Concept Trace A set of spans that form a call tree structure, forms the trace of the re ...
- sqoop导入导出
sqoop产生背景 什么是sqoop sqoop的优势 sqoop1与sqoop2的比较 为什么选择sqoop1 sqoop在hadoop生态体系中的位置 sqoop基本架构 sqoop import ...
- SurFS:共享式和分布式集群各取所长
http://www.ccidnet.com/2016/0811/10168835.shtml 一个集群系统可以做成三层定义,也就是后端存储访问层.沟通协作层.前端数据访问层,如果愣是要给每个层起个洋 ...
- bzoj2961 共点圆 (CDQ分治, 凸包)
/* 可以发现可行的圆心相对于我们要查询的点是在一个半平面上, 然后我们要做的就是动态维护凸壳然后用这个半平面去切它 看看是否是在合法的那一面 然后cdq分治就可以了 代码基本是抄的, */ #inc ...