CodeForces - 877C
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.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the size of the map.
Output
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.
Examples
- 2
- 3
2 1 2
- 3
- 4
2 1 3 2- 在一个1*N的格子里很多坦克,你从高空不知道哪些格子里有坦克,但仍然需要扔炸弹把坦克全都炸毁,坦克第一次被炸到后,一定会向前或者向后移一个格子(第一个格子里的坦克只会向后移一个格子,
最后一个格子里的坦克只会向前移一个格子),当坦克被第二次炸到的时候才会被炸毁,问你怎样炸,才能使耗费的炸弹最少。- 不要一看到这种题就感到无从下手,它肯定是有规律的。
- 在偶数区间里的坦克移动一次后就都到了奇数区间里,奇数区间里的坦克移动一次后就又到了偶数区间里,于是一个大胆的想法就产生了,先偶数区间炸一遍,再奇数区间炸一遍,最后再偶数区间炸一遍。经验正后,可行。
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- #include<string>
- #include<cmath>
- #include<algorithm>
- #include<queue>
- #include<stack>
- #include<deque>
- #include<map>
- #include<iostream>
- using namespace std;
- typedef long long LL;
- const double pi=acos(-1.0);
- const double e=exp();
- const int N = ;
- int main()
- {
- LL i,p,j,n;
- LL ans=,x,y;
- scanf("%lld",&n);
- while()
- {
- ans=n;
- for(i=; i<=n; i+=)
- {
- //if(i!=n)
- ans++;
- }
- printf("%lld\n",ans);
- if(n>=)
- printf("");
- for(i=; i<=n; i+=)
- printf(" %lld",i);
- for(i=; i<=n; i+=)
- printf(" %lld",i);
- for(i=; i<=n; i+=)
- {
- printf(" %lld",i);
- }
- putchar('\n');
- break;
- }
- return ;
- }
CodeForces - 877C的更多相关文章
- Codeforces 877C Slava and tanks(思维)
题目链接:http://codeforces.com/problemset 题目大意:有n个格子,某些格子里可能有一个或多个坦克,但不知道具体位置,每个坦克被轰炸一次就会移动到相邻的格子里(第1个格子 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- springmvc值传递
1.页面向后台传值 A.HttpServletRequest方式: package com.rong.controller; import javax.annotation.Resource; imp ...
- css新增UI方案
一.文本新增样式 opacity 不透明度 h1{ margin: 100px auto; opacity: 0.5; } </style> </head> <body& ...
- Objective - C 之延展
延展:为已有的类新增私有方法,只能在本类中使用 一.创建过程: 二.总结: 1.延展只有.h文件,在其中写新方法的声明,在原本的类(Person)中写方法的实现: 2.上述的方法其实很不安全,因为如果 ...
- php PDO操作类
<?php /*//pdo连接信息 $pdo=array("mysql:host=localhost;dbname=demo;charset=utf8","root ...
- Android性能测试工具APT
APT源码地址:https://code.csdn.net/Tencent/apt APT,Android Performance Testing Tools,适用于开发自测和定位性能瓶颈,帮助测试人 ...
- NoSQL - Redis应用场景
问题的引入 DB(Oracle.MySQL.Postgresql等)+Memcached 这种架构模式在我们生产环境中十分常见,一般我们通过Memcached将热点数据加载到cache,应用 ...
- java中的error该不该捕获
写java程序时,通常会被提示捕获异常,而又有一些异常是不需要强制捕获的,这是一个被说烂了的话题.像我一样从其他语言转过来的人确实有点迷惑,那我以我的理解重新解释一遍吧. 异常的基类是Exceptio ...
- [poi2011]bzoj 2277 —— strongbox·[洛谷3518]
·问题描述· 有一个密码箱,0到n-1中的某些数是它的密码.且满足:如果a和b都是它的密码,那么(a+b)%n也是它的密码.某人试了k次密码,前k-1次都失败了,最后一次成功. 问:该密码箱最多有多少 ...
- Doves and bombs UVA - 10765(统计割顶所连接的连通块的数量)
题意:给定一个n个点的连通的无向图,一个点的“鸽子值”定义为将它从图中删去后连通块的个数. 求对应的点 和 每个点的“鸽子值” 用一个数组在判断割顶的那个地方 累加标记一下所连接的连通块的数量即可 初 ...
- Javascript面向对象三大特性(封装性、继承性、多态性)详解及创建对象的各种方法
Javascript基于对象的三大特征和C++,Java面向对象的三大特征一样,都是封装(encapsulation).继承(inheritance )和多态(polymorphism ).只不过实现 ...