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 ...
随机推荐
- Application.ProcessMessages用法
参考:http://cqujsjcyj.iteye.com/blog/380926 我想你可能还有点模糊.举个例子容易明白:假如你的窗体上有两个按钮,一个“计算”,一个“停止”, 如果你的计算是密集运 ...
- html5 Canvas绘制图形入门详解
html5,这个应该就不需要多作介绍了,只要是开发人员应该都不会陌生.html5是「新兴」的网页技术标准,目前,除IE8及其以下版本的IE浏览器之外,几乎所有主流浏览器(FireFox.Chrome. ...
- ASCIIHexDecode,RunLengthDecode
public static byte[] ASCIIHexDecode(byte[] data) { MemoryStream outResult = new MemoryStream(); bool ...
- 序列化 Serializable
1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态(也就是实例变量,不是方法),并且可以把保存的对象状态再读出来.虽然你可以用你自己的各种各样的方法来保存object states,但 ...
- 日常UVA题目英语积累
quote应该是引号的意思 Two matches (i, j) and (p, q) are called independent when i = p if and only if j = q. ...
- 【转】【异常处理】Incorrect string value: '\xF0\x90\x8D\x83...' for column... Emoji表情字符过滤的Java实现
http://blog.csdn.net/shootyou/article/details/44852639 Emoji表情字符现在在APP已经广泛支持了.但是MySQL的UTF8编码对Emoji字符 ...
- LoadRunner检查点
web_reg_find("Text=ABC", "SaveCount=abc_count", LAST);51Testing软件测试网V?2Rs.J Gmdw ...
- CentOS下Redis安装配置小结
Redis是REmote DIctionary Server的缩写. 是一个使用 C 语言写成的,开源的 key-value 非关系型数据库.跟memcached类似,不过数据可以持久化. Redis ...
- 一个android样本的过保护
前段时间处理一个android样本,样本本身作用不大,但是加了保护,遂做一个过保护的记录 通过dex2jar将dex转为jar文件的时候发现无法成功,通过抛出的异常可知,此处MainActivity: ...
- Codeforces Round #355 (Div. 2)-C
C. Vanya and Label 题目链接:http://codeforces.com/contest/677/problem/C While walking down the street Va ...