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 ...
随机推荐
- 模拟远程SSH执行命令的编解码说明
模拟一个SSH“远程”执行命令并获取命令结果的一个程序: 1.在C/S架构下,当客户端与服务器建立连接(这里以TCP为例)后,二者可以不断的进行数据交互.SSH远程可以实现的效果是客户端输入命令可以在 ...
- UML类关系:依赖、关联、聚合、组合
1,依赖关系(Dependency) 单向,表示一个类依赖于另一个类的定义,其中一个类的变化将影响另外一个类,是一种“use a”关系 如果A依赖于B,则B表现为A的局部变量,方法参数,静态方法调用等 ...
- 修改了jdk在环境变量中的路径怎么cmd中的jdk版本没有变
把path路径下的jdk配置放在前面%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot ...
- androidstudio在创建new project时,窗口太大,看不到下面确定按钮的解决方法
点击File-->setting-->Appearance将里面的Override default fonts by(not recommended)打钩去掉. 这个是目前找到唯一办法.
- Solr使用in语法查询
Solr可以用AND.|| 布尔操作符 表示查询的并且, 用OR.&& 布尔操作符 表示或者 用NOT.!.-(排除操作符不能单独与项使用构成查询)表示非 如果要用在查询的时候使用 ...
- WPF Storyboard 动画播放完毕时触发的事件
/*故事版*/ Storyboard ClSto2; public PopUpWindow() { /*播放完毕,将当前窗体关闭*/ ClSto2.Completed += (s, e) => ...
- Es6入门解构
变量解构赋值:数组和对象中提取值,对变量进行赋值 1️⃣模式匹配:只要等号左右两边的模式相同,左边的变量就会被赋予对应的值 2️⃣不完全解构:等号左边的模式匹配等号右边数组的部分 默认值:解构赋值允许 ...
- 【Jmeter自学】Jmeter性能测试报告(八)
http://www.cnblogs.com/YatHo/p/6092599.htmlhttp://blog.csdn.net/xiaojianpitt/article/details/4821554 ...
- win7 数据源只有 SQL SERVER, WIN7 64bit 环境使用 access 作为 CIS的数据源
最近换了个工作电脑,安装的是 WIN7 64BIT,结果配置CIS数据源的时候出现问题了,默认的数据源只有 SQL SERVER,没有ACCESS的数据源.后来在网上寻找了一圈后,找到了解决方法: C ...
- 我也说说Nginx——先搞搞清楚
一.Nginx的诞生 这个很多文章里都有,总之就是当年啊有个技术困难叫C10K问题,就是如何解决10万个客户端的并发请求问题.然后有个俄罗斯大牛某某某,在02年使用C语言搞了个东东声称可以处理每天5亿 ...