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 ...
随机推荐
- [UE4]使用DataTable
- 皮卡丘检测器-CNN目标检测入门教程
目标检测通俗的来说是为了找到图像或者视频里的所有目标物体.在下面这张图中,两狗一猫的位置,包括它们所属的类(狗/猫),需要被正确的检测到. 所以和图像分类不同的地方在于,目标检测需要找到尽量多的目标物 ...
- CS229 6.4 Neurons Networks Autoencoders and Sparsity
BP算法是适合监督学习的,因为要计算损失函数,计算时y值又是必不可少的,现在假设有一系列的无标签train data: ,其中 ,autoencoders是一种无监督学习算法,它使用了本身作为标签以 ...
- SQL Server 查询性能优化——创建索引原则(一)
索引是什么?索引是提高查询性能的一个重要工具,索引就是把查询语句所需要的少量数据添加到索引分页中,这样访问数据时只要访问少数索引的分页就可以.但是索引对于提高查询性能也不是万能的,也不是建立越多的索引 ...
- Vue学习记录(二)
一.指令 指令是Vue.js中一个重要的特性,主要提供了一种机制将数据的变化映射为DOM行为.当数据变化时,指令会依据设定好的操作对DOM进行修改,这样就可以只关注数据的变化,而不用去管理DOM的变化 ...
- python连接数据库——create_engine和conn.cursor
python操作数据库的方法: 一种是导入sqlalchemy包,另一种是导入psycopg2包. 具体用法如下(此处以postgre数据库举例) 第一种: # 导入包 from sqlalchemy ...
- c# Color 颜色设置
#region 笔刷颜色 public SolidColorBrush col(byte a, byte r, byte g, byte b) { #region 颜色说明 //Color.FromA ...
- this 基础使用方法
在Java中,this是调用类中变量和内部类的构造方法的关键词,在对象有同名变量时,可以指定类的变量. 例子1: package example_1; import java.lang.*; publ ...
- fabric-network_setup.sh安装脚本分析
在进行镜像安装前,提供了一个sample脚本的下载,可以使用该脚本进行容器的启停.这里对该脚本进行分析. fabric/release/linux-amd64/network_setup.sh 脚本提 ...
- SecureCRT连接linux,Hive中无法使用删除键