// 多校6 1010 HDU5802 Windows 10
// 题意:从p到q有三种操作,要么往上升只能1步,要么往下降,如果连续往下降就是2^n,
// 中途停顿或者向上,下次再降的时候从1开始。问最少次数
// 思路:
// 1.下么一直往下降,到q的下方,然后再往上升。
// 2.或者往下降到离q最近的一个点再停顿一下 然后继续往下降
// 第一种的时候,上升的时候要减去之前停顿的次数,也就是说我可以提前上升一格,不用停顿。
// 应为上升一格的话,一定是要往上一格 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL dfs(LL p,LL q,LL stop,LL ans){
if(p==q) return ans;
LL cnt=;
while(p-(<<cnt)+>q) cnt++;
if(p-(<<cnt)+==q) return ans+cnt;
LL dis=q-max(0LL,(LL)p-(<<cnt)+);
LL tem=cnt+max(0LL,dis-stop);
return min(tem+ans,dfs(p-(<<(cnt-))+,q,stop+,ans+cnt));
}
int main(){
int T;
scanf("%d",&T);
while(T--){
LL p,q;
scanf("%I64d%I64d",&p,&q);
if(p<=q){
printf("%I64d\n",q-p);
continue;
}
else{
LL ans=dfs(p,q,,);
printf("%I64d\n",ans);
}
}
return ;
}

多校6 1010 HDU5802 Windows 10 dfs的更多相关文章

  1. hdu5802 Windows 10 贪心

    Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  2. hdu 5802 Windows 10 (dfs)

    Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. hdu-5802 Windows 10(贪心)

    题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others ...

  4. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  5. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  6. HDU 5802 Windows 10

    传送门 Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  7. hdu 5802 Windows 10 贪贪贪

    传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...

  8. windows 10开启bash on windows,配置sshd,部署hadoop

    1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...

  9. HDU 4685 Prince and Princess (2013多校8 1010题 二分匹配+强连通)

    Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

随机推荐

  1. NewPascal(也许只是对FreePascal的一种封装)

    NewPascal is a breath of fresh air and long tradition! NewPascal offers a ready-to-be-used and up-to ...

  2. [转]useradd 与adduser的区别

    转自:Deit_Aaron的专栏 添加用户:useradd -m 用户名  然后设置密码  passwd 用户名 删除用户:userdel  -r  用户名 1. 在root权限下,useradd只是 ...

  3. UVa 10075 - Airlines

    航线算球面距离,需要经纬度转空间坐标. 任意两点间距离用Floyd求出来,查询时直接查表. #include <cstdio> #include <map> #include ...

  4. Entity Framework学习 - 2.增删改查

    1.增加数据 PirateBayEntities db = new PirateBayEntities(); T_Tests test = new T_Tests(); test.Name = &qu ...

  5. C库函数手册(ctype.h)

    ctype.h函数说明:int isalpha(int ch)  若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0 int isdigit(int ch)  若ch是数字('0'- ...

  6. java中的线程创建和使用

    Java中实现多线程有两种途径:继承Thread类或者实现Runnable接口.Runnable是接口,建议用接口的方式生成线程,因为接口可以实现多继承,况且Runnable只有一个run方法,很适合 ...

  7. bzoj1717: [Usaco2006 Dec]Milk Patterns 产奶的模式

    后缀数组+二分答案+离散化.(上次写的时候看数据小没离散化然后一直WA...写了lsj师兄的写法. #include<cstdio> #include<cstring> #in ...

  8. ASP.NET 共用类库1

    using System; using System.Collections.Generic; using System.Text; using System.Web; using System.We ...

  9. Qt 多线程学习

    最近的项目上用到了关于多线程的知识,自己也比较感兴趣,所以就拿了那本<C++ GUI Qt4 编程>来学习. 这本书的第14章是关于多线程的知识,使用的Qt版本是Qt4.x.在下用的是最新 ...

  10. 模仿 "淘宝彩票" 的随机选球投注效果!

    我个人比较喜欢看网页的效果,前几天看了淘宝的“淘宝彩票”,今天仿造做了一个,我觉得比淘宝的体验要好. 查看 “淘宝彩票” 的网页源码发现,主要是用到了Css3 transform 的 Matrix 来 ...