URAL 1117. Hierarchy(DP)
这破题,根本看不懂题意啊。。。题意:一棵中序遍历是1 2 3 4 5...的满二叉树,从a a+1 a+2 a+3 b,总共多少步。x到y的距离为中间有多少个点。a > b没注意2Y。
#include <cstring>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
int bin[];
int judge(int x)
{
int i,temp;
if(x <= )
return ;
for(i = ;i >= ;i --)
{
if(x&(<<i))
{
temp = x-(<<i);
if(temp)
return bin[i] + judge(temp) + i - ;
else
return bin[i];
}
}
return ;
}
int main()
{
int i,a,b;
bin[] = bin[] = ;
for(i = ;i <= ;i ++)
{
bin[i] = *bin[i-] + i-;
}
scanf("%d%d",&a,&b);
if(a > b)
swap(a,b);
printf("%d\n",judge(b)-judge(a));
return ;
}
URAL 1117. Hierarchy(DP)的更多相关文章
- Ural 1018 (树形DP+背包+优化)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 题目大意:树枝上间连接着一坨坨苹果(不要在意'坨'),给 ...
- ural 1039 树dp
http://acm.timus.ru/problem.aspx?space=1&num=1039 1039. Anniversary Party Time limit: 0.5 second ...
- URAL 1427. SMS(DP+单调队列)
题目链接 我用的比较传统的办法...单调队列优化了一下,写的有点搓,不管怎样过了...两个单调队列,存两个东西,预处理一个标记数组存... #include <iostream> #inc ...
- URAL 1244. Gentlemen(DP)
题目链接 这题不难啊...标记一下就行了.表示啥想法也没有. #include <cstring> #include <cstdio> #include <string& ...
- ural 1018(树形dp)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 思路:典型的树形dp,处理的时候类似于分组背包,dp[i] ...
- URAL 1056(树形DP)
1056. Computer Net Time limit: 2.0 second Memory limit: 64 MB Background Computer net is created by ...
- URAL 1057 数位dp
题目传送门http://acm.timus.ru/problem.aspx?space=1&num=1057 最近在学习数位dp,具体姿势可以参照这篇论文:http://wenku.baidu ...
- ural 1017. Staircases(dp)
http://acm.timus.ru/problem.aspx?space=1&num=1017 题意:有n块砖,要求按照严格递增的个数摆放成楼梯,求楼梯的摆放种类数. 思路:状态转移方程: ...
- URAL 1119. Metro(DP)
水题. #include <cstring> #include <cstdio> #include <string> #include <iostream&g ...
随机推荐
- 【javascript】 for循环小技巧
最近在读[Jquery技术内幕],里面介绍了一种js for循环的实用写法. 一般写for循环是这么写的: var elemts = [1,2,3,4,5]; for(var i=0; i<el ...
- 《图形学》实验四:中点Bresenham算法画直线
开发环境: VC++6.0,OpenGL 实验内容: 使用中点Bresenham算法画直线. 实验结果: 代码: //中点Bresenham算法生成直线 #include <gl/glut.h& ...
- Linux进程状态 ( Linux Process State Codes)
进程状态代码及说明: STATE代码 说明 D 不可中断的睡眠. 通常是处于I/O之中. R 运行中/可运行. 正处于运行队列中. S 可中断的睡眠. 等待某事件发生. T 已停止. 可能是因为she ...
- jqueryEasyUI:tabs扩展:给tabs组件绑定双击事件 分类: JqueryEasyUI 2014-09-29 14:36 537人阅读 评论(0) 收藏
实现代码: $.extend($.fn.tabs.methods, { /** * 绑定双击事件 * @param {Object} jq * @param {Object} caller 绑定的事件 ...
- android 入门-引用库项目
http://blog.csdn.net/arui319/article/details/6831164
- C# NamePipe使用小结
最近在一次项目中使用到了C#中命名管道,所以在此写下一篇小结备忘. 为什么要使用命名管道呢?为了实现两个程序之间的数据交换.假设下面一个场景.在同一台PC上,程序A与程序B需要进行数据通信,此时我们就 ...
- uC/OS II原理分析及源码阅读(一)
uC/OS II(Micro Control Operation System Two)是一个可以基于ROM运行的.可裁减的.抢占式.实时多任务内核,具有高度可移植性,特别适合于微处理器和控制器,是和 ...
- 介绍n款计算机视觉库/人脸识别开源库/软件
计算机视觉库 OpenCV OpenCV是Intel®开源计算机视觉库.它由一系列 C 函数和少量 C++ 类构成,实现了图像处理和计算机视觉方面的很多通用算法. OpenCV 拥有包括 300 多个 ...
- C++ find 函数用法
头文件 #include <algorithm> 函数实现 template<class InputIterator, class T> InputIterator find ...
- 在Salesforce中添加Workflow Rule
在Salesforce中可以添加Workflow Rule来执行特定的动作,比如说:当Object的某个字段发生变化时,根据变化的值去修改其他field,和Trigger的功能很类似,不过Trigge ...