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的更多相关文章

  1. zoj 1539 Lot

    /*理解题意后,发现最后剩下的都是个数并不是和奇数偶数等有直接的关系,所以我们直接从数量入手 比如11会被分为5,6.5再分2,3.6再分3,3只要剩下三个就算一种,少于三个不用算.大于3个继续分 很 ...

  2. zoj 1539 Lot 简单DP 记忆化

    Lot Time Limit: 2 Seconds      Memory Limit: 65536 KB Out of N soldiers, standing in one line, it is ...

  3. ZOJ - 1539 记忆化搜索

    注意不要仅搜DP(1e7),因为这不是线性的 #include<iostream> #include<algorithm> #include<cstdio> #in ...

  4. JavaWeb 后端 <二> 之 Servlet 学习笔记

    一.Servlet概述 1.什么是Servlet Servlet是一个运行在服务器端的Java小程序,通过HTTP协议用于接收来自客户端请求,并发出响应. 2.Servlet中的方法 public v ...

  5. HTML5 3D 粒子波浪动画特效DEMO演示

    需要thress.js插件:     http://github.com/mrdoob/three.js // three.js - http://github.com/mrdoob/three.js ...

  6. L - Connections in Galaxy War - zoj 3261

    题意:有一个帝国在打仗,敌方会搞一些破坏,总共用N个阵地,每个阵地都有一个武力值,当第一地方收到攻击的时候他可以进行求助,当然求助的对象只能是武力值比他高的,如果求助失败就输出 ‘-1’, 求助成功就 ...

  7. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  8. ZOJ 2334 Monkey King

    并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子                       Monkey King ...

  9. ZOJ 3494 BCD Code(AC自动机+数位DP)

    BCD Code Time Limit: 5 Seconds      Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...

随机推荐

  1. python学习笔记:第6天 小数据池和编码转换

    目录 1. id 和 == 2. 小数据池 3. 编码和解码 1. id 和 == id:id是一个内置的函数,可以查看变量存放的内存地址(实际上不是真正的物理地址,这里暂时这样理解),用于判断是变量 ...

  2. Python递归与迭代

    1.递归与迭代: 递归和迭代都是循环的一种.简单地说,递归是重复调用函数自身实现循环.迭代是函数内某段代码实现循环,而迭代与普通循环的区别是:循环代码中参与运算的变量同时是保存结果的变量,当前保存的结 ...

  3. Python在线编程环境

    除了安装Python的IDE之外,也可以使用在网页中随时随地编写Python程序. Python官网:https://www.python.org/shell Python123:https://py ...

  4. STM32 时钟配置的坑

    今天在调试公司的一款产品的时候发现8M的晶振用完了,于是找了一个16M的替代 坑爹的就在这里,明明已经把时钟按照时钟树配置好了,但是串口等外设一直无法正常工作 折腾了一下午,终于发现这位老兄的文章ht ...

  5. GeekOS: 一、构建基于Ubuntu9.04的实验环境

    参考:http://www.cnblogs.com/wuchang/archive/2009/05/05/1450311.html 补充:在最后步骤中,执行bochs即可弹出运行窗口

  6. mac, start sublime from terminal

    1.where is sublime CLI /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl 2. run sublime ...

  7. 北京Uber优步司机奖励政策(1月27日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  8. hdu1848Fibonacci again and again(sg函数)

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  9. hdu1159Common Subsequence(动态规划)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  10. GIt学习第二天之版本回退、工作区和暂存区

    搬运自 ‘廖雪峰的官方网站’ 地址:https://www.liaoxuefeng.com/ 1.版本回退 在Git中,我们用git log命令显示从最近到最远的提交日志,如果嫌输出信息太多,看得眼花 ...