ZOJ 1539 L-Lot
https://vjudge.net/contest/67836#problem/L
Out of N soldiers, standing in one line, it is required to choose several to send them scouting.
In order to do that, the following operation is performed several times: if the line consists of more than three soldiers, then all soldiers, standing on even positions, or all soldiers, standing on odd positions, are taken away. The above is done until three or less soldiers are left in the line. They are sent scouting. Find, how many different groups of three scouts may be created this way.
Note: Groups with less than three number of soldiers are not taken into consideration.
0 < N <= 10 000 000
Input
The input file contains the number N.
Process to the end of file.
Output
The output file must contain the solution - the amount of variants.
Sample Input
10
4
Sample Output
2
0
时间复杂度:$O(n)$
代码1:
#include<bits/stdc++.h>
using namespace std; const int maxn = 1e7 + 10;
int num[maxn]; int main()
{
for(int i = 1; i <= 10000000; i ++) {
if(i < 3) num[i] = 0;
else if(i == 3) num[i] = 1;
else if(i % 2 == 0) num[i] = 2 * num[i / 2];
else num[i] = num[i / 2] + num[i / 2 + 1];
} int n;
while (~scanf("%d", &n))
printf("%d\n", num[n]);
return 0;
}
ZOJ 1539 L-Lot的更多相关文章
- zoj 1539 Lot
/*理解题意后,发现最后剩下的都是个数并不是和奇数偶数等有直接的关系,所以我们直接从数量入手 比如11会被分为5,6.5再分2,3.6再分3,3只要剩下三个就算一种,少于三个不用算.大于3个继续分 很 ...
- zoj 1539 Lot 简单DP 记忆化
Lot Time Limit: 2 Seconds Memory Limit: 65536 KB Out of N soldiers, standing in one line, it is ...
- ZOJ - 1539 记忆化搜索
注意不要仅搜DP(1e7),因为这不是线性的 #include<iostream> #include<algorithm> #include<cstdio> #in ...
- JavaWeb 后端 <二> 之 Servlet 学习笔记
一.Servlet概述 1.什么是Servlet Servlet是一个运行在服务器端的Java小程序,通过HTTP协议用于接收来自客户端请求,并发出响应. 2.Servlet中的方法 public v ...
- HTML5 3D 粒子波浪动画特效DEMO演示
需要thress.js插件: http://github.com/mrdoob/three.js // three.js - http://github.com/mrdoob/three.js ...
- L - Connections in Galaxy War - zoj 3261
题意:有一个帝国在打仗,敌方会搞一些破坏,总共用N个阵地,每个阵地都有一个武力值,当第一地方收到攻击的时候他可以进行求助,当然求助的对象只能是武力值比他高的,如果求助失败就输出 ‘-1’, 求助成功就 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ 2334 Monkey King
并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子 Monkey King ...
- ZOJ 3494 BCD Code(AC自动机+数位DP)
BCD Code Time Limit: 5 Seconds Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...
随机推荐
- 大数据学习--day08(hnapp 后台系统开发、面向对象)
hnapp 后台系统开发.面向对象 利用前面所学的知识,写一个控制台登陆注册后台界面 package sy180918.hnapp.array; import java.util.Arrays; im ...
- openWrt libubox组件之uloop原理分析
1. libubox概述 libubox是openwrt新版本中的一个基础库,有很多应用是基于libubox开发的,如uhttpd,netifd,ubusd等. libubox主要提供以下两种功 ...
- 利用.NET Code Contracts实现运行时验证
.NET的Contract类库是Declarative Programming实践的一部分,可以对日常编程带来很多好处: 提高代码可读性,使用者一看Require, Ensure就知道这方法接受什么输 ...
- pygame---制作一只会转弯的小乌龟
Pygame Pygame是跨平台Python模块,专为电子游戏设计,包含图像.声音.建立在SDL基础上,允许实时电子游戏研发而无需被低级语言(如机器语言和汇编语言)束缚. 包含图像.声音. 建立在S ...
- 北京Uber优步司机奖励政策(10月26日~11月1日)
用户组:优步北京人民优步A组(适用于10月26日-11月1日) 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/ ...
- Ceres优化
Ceres Solver是谷歌2010就开始用于解决优化问题的C++库,2014年开源.在Google地图,Tango项目,以及著名的SLAM系统OKVIS和Cartographer的优化模块中均使用 ...
- jQuery tableExport导出 excel
上篇写的是jQuery 导出word,就试试导出excel.看见网上写的很乱,我这就把我写的整理下来,有部分来自网上capy 1. js文件的引用 <script type="te ...
- macOS 10.13 High Sierra PHP开发环境配置
命令:sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo rm -rf /Library/StartupItems/MySQLCOM ...
- Python中安装Prophet
1. 先安装pystan依赖 按照https://pystan.readthedocs.io/en/latest/windows.html说明,请使用如下命令 conda install libpyt ...
- 结合BeautifulSoup和hackhttp的爬虫实例
网页页数的改变 headers头不添加