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. JS通用弹窗,确定,取消可以回调方法。

    <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/j ...

  2. hive优化-数据倾斜优化

    数据倾斜解决方法,通常从以下几个方面进行考量: 业务上丢弃  •  不参与关联:在on条件上直接过滤 •  随机数打散:比如 null.空格.0等“Other”性质的特殊值  倾斜键记录单独处理 •  ...

  3. LCD驱动程序编写

    学习目标:编写LCD驱动程序,熟悉根据芯片手册分析时序图,配置寄存器,并测试LCD程序. 一.LCD驱动程序编写 步骤: 1)分配fb_info结构体 2)设置fb_info结构体 a. 固定参数 b ...

  4. python之内存与编码的那点事

    一.初始编码 ASCII 码不支持中文 是py2版本中的默认编码 ​Unicode 万国码, 英文使用16位(即两个字节​),中文使用32位(四个字节) ​utf-8 美国最少使用八位(1字节), 欧 ...

  5. go内建容器-字符和字符串操作

    1.基础定义 在基础语法篇提到过golang的rune相当于其他编程语言的char,其本质是一个int32(四字节),用[]rune来转换一个字符串时,得到的是个解码后的结果,存储在新开辟的[]run ...

  6. P1535 游荡的奶牛

    P1535 游荡的奶牛 题目描述 Searching for the very best grass, the cows are travelling about the pasture which ...

  7. 一、Lambda表达式

    一.Lambda是什么? Lambda是一个匿名函数,我们可以把Lambda理解为是一段可以传递的代码.可以写出简洁.灵活的代码.作为一种更紧凑的代码风格,使java的语言表达能力得到提升. 二.La ...

  8. Spring的cache缓存介绍

    从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该 ...

  9. 使用PowerDesign15反向生成数据库

           在Pd15中建立物理模型后,可以通过反向工程直接生成数据库的表结构.主要有以下几个步骤: 1. 首先设置一下数据库配置,选择对应要使用的数据库(此处选择Sql Server 2008 R ...

  10. ORA-15032、ORA-15033—Linux环境

    SQL> alter diskgroup DATA add failgroup DATA_0000 disk '/dev/raw/raw12'; alter diskgroup DATA add ...