codeforces877c
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 翻译就算了吧 谷歌比我翻译的好不少
抽象一下:每个tank两滴血,tank排列在1*n的网格中,每个网格中有多个tank,你可以在空中进行轰炸,每个tank被炸到后,都会往左右两个方向挑一个移动,炸两次就死了,求用多少炸弹能炸死所有的tank 这个题我没想出来,还是看的别人的题解,但是好多题解都没有证明为什么这么炸这是最佳结论,包括官方题解都说it's easy to prove the strategy is optimal 可能这就是差距吧,我想了好长时间都
想不明白
当然现在也想不明白,之后看能不能在补上吧 先输出偶数位,在输出奇数位,再输出偶数位
丑陋的代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int i,j,n;
scanf("%d",&n);
printf("%d\n",n+n/2);
for(i = 2; i <= n; i += 2)
printf("%d ",i);
for(i = 1; i <= n; i += 2)
printf("%d ",i);
for(i = 2; i <= n - 2; i += 2)
printf("%d ",i);
printf("%d\n",i);
}
codeforces877c的更多相关文章
随机推荐
- python添加fluent日志记录
istio默认会进行日志的记录,但是仅仅记录到服务.以及服务之间调用的信息,不记录业务日志. 如: 所以需要添加业务日志记录. 1.python引入package fluentmsgpack 2.代码 ...
- C# 获取 存储过程 返回值
C#获取存储过程的返回值,这一方法,总是容易忘,今天给贴出来,以方便下次使用 存储过程: CREATE PROCEDURE [dbo].[Proc_GetInfo] ), ) out ...
- HTML JavaScript语法练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 希尔排序和归并排序(java实现)
希尔排序 希尔排序算法实际上是一种特殊的插入排序,由DL.Shell于1959年提出而得名. 算法思想:希尔排序使数组中任意间隔为h的元素都是有序的,这些数组称为h有序数组,对于每个h,按插入排序进行 ...
- iOS常用代码总结
1.读取图片NSString *path = [[NSBundle mainBundle] pathForResource"icon" ofType"png"] ...
- 多个tomcat shutdown.sh 导致无法正常关闭的问题
1. 今天启动两个tomcat , 但是由于个人失误,只改了以下两个端口 ,忘记修改shutdown相应端口.这是启动两个tomcat ,可以正常启动并访问.. <Connector port= ...
- SpringBoot注册Servlet/Filter/Listener
由于SpringBoot默认是以jar包的方式启动嵌入式的Servlet容器来启动SpringBoot的web应用,那么没有web.xml文件,如何配置我们的三大Web基础组件呢? 通过使用XXXRe ...
- [C#]RichTextBox实现拖放
amespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeC ...
- spring学习 十三 注解AOP
spring 不会自动去寻找注解,必须告诉 spring 哪些包下的类中可能有注解,也就是要开启注解扫描,注解的包是spring-context.jar,所以在配置文件中还要引入context约束,也 ...
- TCP的11种状态(转载)
TCP的11种状态 TCP三次握手建立连接 Tcp头部 六个标志位中,我们要用到三个: SYN:SYN= 1 表示这是一个连接请求或连接接受报文.在建立连接时用来进行同步序号(个人理解是,在建立连接的 ...