// 多校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. 【动态规划】流水作业调度问题与Johnson法则

    1.问题描述:     n个作业{1,2,…,n}要在由2台机器M1和M2组成的流水线上完成加工.每个作业加工的顺序都是先在M1上加工,然后在M2上加工.M1和M2加工作业i所需的时间分别为ai和bi ...

  2. HTML5入门6---视频播放按钮

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. shutdown -s -t

    import java.io.*; import java.awt.*; public class HackDemo{ public static void main(String args[])th ...

  4. 每用户订阅上的所有者 SID 不存在 (异常来自 HRESULT:0x80040207)

    出现这个问题是因为pQueryFilter.WhereClause = "RoomNumber=" +cmbFromPoint.SelectedItem;中的cmbFromPoin ...

  5. Servlet的应用

    1.重定向     HttpServletRequest接口提供的sendRedirect()方法用于生产302响应码和Location响应头,从而通知客户端去重新访问Location响应头中指定的U ...

  6. eclipse运行emulator时,PANIC:Could not open emulator的解决办法

    使用eclipse启动emulator的时候,出现PANIC:Could not open emulator,模拟器无法正常的运行. 经过搜索得知,因为我的SDK的环境变量出问题,需要重新配置下环境变 ...

  7. [51NOD1126]求递推序列的第n项(矩阵快速幂)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1126 存在参数a,b为负数的情况.这时候要这么处理: 根据mo ...

  8. linux/unix网络编程之 poll

    转自http://www.cnblogs.com/zhuwbox/p/4222382.html poll 与 select 很类似,都是对描述符进行遍历,查看是否有描述符就绪.如果有就返回就绪文件描述 ...

  9. UVa 1262 (第k字典序) Password

    题意: 给出两个6行5列的字母矩阵,一个密码满足:密码的第i个字母在两个字母矩阵的第i列均出现. 然后找出字典序为k的密码,如果不存在输出NO 分析: 我们先统计分别在每一列均在两个矩阵出现的字母,然 ...

  10. UVa 10054 The Necklace【欧拉回路】

    题意:给出n个珠子,珠子颜色分为两半,分别用1到50之间的数字表示, 现在给出n个珠子分别的颜色,问是否能够串成一个环.即为首尾相连,成为一个回路 判断是否构成一个环,即判断是否为欧拉回路,只需要判断 ...