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:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxn = 1e7 + 10;
  5. int num[maxn];
  6.  
  7. int main()
  8. {
  9. for(int i = 1; i <= 10000000; i ++) {
  10. if(i < 3) num[i] = 0;
  11. else if(i == 3) num[i] = 1;
  12. else if(i % 2 == 0) num[i] = 2 * num[i / 2];
  13. else num[i] = num[i / 2] + num[i / 2 + 1];
  14. }
  15.  
  16. int n;
  17. while (~scanf("%d", &n))
  18. printf("%d\n", num[n]);
  19. return 0;
  20. }

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. hadoop学习笔记——用python写wordcount程序

    尝试着用3台虚拟机搭建了伪分布式系统,完整的搭建步骤等熟悉了整个分布式框架之后再写,今天写一下用python写wordcount程序(MapReduce任务)的具体步骤. MapReduce任务以来H ...

  2. IAP笔记

    1)   首先是IAP BootLoader程序设置:根据common.h里面的宏定义,设置BootLoader所占用的Flash空间. 2)   设置IAP UserApp程序设置:该型号Flash ...

  3. 【BZOJ5299】【CQOI2018】解锁屏幕(动态规划,状态压缩)

    [BZOJ5299][CQOI2018]解锁屏幕(动态规划,状态压缩) 题面 BZOJ 洛谷 Description 使用过Android手机的同学一定对手势解锁屏幕不陌生.Android的解锁屏幕由 ...

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

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

  5. SQL计算出百分比

    有clients和lead_sources俩表.mysql数据库. lead_sources表结构类似: clients表中的lead_source_id是外键.现在要统计某时间段内client内每种 ...

  6. 华天正real210开发板测试-第1篇

    1. 网上买的real210二手开发板,今天刚到测试一下 2. 启动方式,不过目前唯一的问题是没有开发资料,然后给原厂发了份邮件要资料,原厂爽快的给了,必须给华天正这服务态度点个赞啊 3. 调到nan ...

  7. L010 linux命令及基础手把手实战总结

    一转眼都快两周没更新了,最近实在太忙了,这两周的时间断断续续的把L010学完了,短短的15节课,确是把前10节的课程全部的运用一遍,从笔记到整理,再到重新理解,最后发布到微博,也确实提升了一些综合性能 ...

  8. libevent学习六(Connect listeners )

      创建与释放 //backlog需要查询平台说明,在linux2.2以后 backlog就变成了已完成连接但未accept的队列的最大值(原来是处于syn状态的,现在换成sysctl 控制的参数tc ...

  9. git基础(2)

    三.查看提交历史日志查看·提交历史:git log 命令一个常用的选项是 -p,用来显示每次提交的内容差异. 你也可以加上 -2 来仅显示最近两次提交如果你想看到每次提交的简略的统计信息,你可以使用 ...

  10. 第四模块:网络编程进阶&数据库开发 第1章·网络编程进阶

    01-进程与程序的概念 02-操作系统介绍 03-操作系统发展历史-第一代计算机 04-操作系统发展历史-批处理系统 05-操作系统发展历史-多道技术 06-操作系统发展历史-分时操作系统 07-总结 ...