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 ...
随机推荐
- JAVA 中的文件读取
1. InputStream / OutputStream处理字节流抽象类:所有输入.输出(内存)类的超类,一般使用 FileInputStream / FileOutputStream 输出字符 u ...
- Python学习:12.Python字符串格式化
字符串格式化 讲解Python这么久,也没有讲解Python的字符串的格式化,那我们今天就来了解一下python字符串格式化的强大之处. 首先我们先理解一下为什么要有字符串的格式化,就是为了方便字符串 ...
- 深入解析Dropout
过拟合是深度神经网(DNN)中的一个常见问题:模型只学会在训练集上分类,这些年提出的许多过拟合问题的解决方案:其中dropout具有简单性并取得良好的结果: Dropout 上图为Dropout的可视 ...
- [原创]python高可用程序设计方法
有时候程序上的bug会导致程序引发诸如段错误的情况而导致程序异常退出,这时用crond服务来检测,就会有一段时间程序处于不可用的情况,为了增强程序的可用性,我们可以让子进程处理业务,而让主进程检测子进 ...
- winform 的语言国际化
http://www.cnblogs.com/codefish/p/4778269.html
- 每天看一片代码系列(一):stream.js
简介 stream.js是一个小型的js库,用于处理stream相关的操作.这里的stream是指一种数据结构,它像数组一样,可以放置多个类型的数据,但是并不限制长度,甚至可以达到无限长.可以对该数据 ...
- linux进程的学习笔记(未完)
1. 进程是程序执行的一个实例,如果16个用户同时运行vi,那么有16个独立的进程,尽管它们共享同一个可执行代码,问题在于FreeRTOS这种系统,是否可以建2个相同的任务,需要注意什么?在linux ...
- 一文带你了解 Raft 一致性协议的关键点
此文已由作者孙建良授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. Raft 协议的发布,对分布式行业是一大福音,虽然在核心协议上基本都是师继 Paxos 祖师爷(lampor ...
- java 的原型模式和clone
原型模式是一种创建型设计模式,在java中可以直接调用object.clone(). 原型模式属于对象的创建模式.通过给出一个原型对象来指明所有创建的对象的类型,然后用复制这个原型对象的办法创建出更多 ...
- Python学习-猜数字游戏
菩萨蛮·黄鹤楼 茫茫九派流中国,沉沉一线穿南北.烟雨莽苍苍,龟蛇锁大江. 黄鹤知何去,剩有游人处.把酒酹滔滔,心潮逐浪高! --coding:UTF-8-- import random secret ...