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. 【Keil】Keil5添加源程序和头文件

    xxx.c就是源程序 xxx.h就是头文件 [源程序添加方法] 双击文件夹,例如图片上的Source,跳出弹窗,选择需要添加的源程序即可 [添加头文件的方法] 1.首先点击图片红框处,或是在文件夹te ...

  2. Centos配置网卡子接口

    1.检查OS是否加载802.1q模块: 方法一: [root@rs2 ~]# modinfo 8021q 方法二: [root@rs2 ~]# modinfo -F filename 8021q 方法 ...

  3. go内建容器-Map

    1.基础定义 golang中的map如同它的函数一样"纯粹",map就是用来存储键值对的容器,别管什么哈希不哈希的(底层已实现),用就行 //创建一个map m := map[st ...

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

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

  5. hive整合sentry,impala,hue之后权限管理操作

    7.Hive授权参考(开启sentry之后,对用户授权用不了,只能针对用户组,grant role testrole to user xxxxxxx; ) 7.1:角色创建和删除 create rol ...

  6. ShimmerTextView

    本文来自网易云社区 作者:孙有军 产品中有一个需求,要求TextView的文字有一个高亮的效果,高亮的同时有跑马灯效果! 本来想在网上找一个现成的用用,比如Facebook出的Shimmer,还有很多 ...

  7. 数据库路由中间件MyCat - 背景篇(2)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MyCat的前世今生 如前文所说,Amoeba.Cobar.MyCat等属于同宗一脉.若Amoeba能继续下 ...

  8. spark 执行架构

    术语定义 Application:Spark Application的概念和Hadoop MapReduce中的类似,指的是用户编写的Spark应用程序,包含了一个Driver 功能的代码和分布在集群 ...

  9. Weka java.lang.reflect.InvocationTargetException

    在用Weka导入数据的时候报 java.lang.reflect.InvocationTargetException 错误,Weka运行包没有给出详细的错误信息,无法查到. 直接调试Weka源码,发现 ...

  10. js函数相关高级用法

    一.惰性载入函数(lazy function) 使用场景:当一个函数中的判断分支只用执行一次(第一次调用时执行),后续不会再变化,则可以使用惰性函数来提高性能. var addEvent = func ...