多校6 1010 HDU5802 Windows 10 dfs
// 多校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的更多相关文章
- hdu5802 Windows 10 贪心
Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 5802 Windows 10 (dfs)
Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu-5802 Windows 10(贪心)
题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- HDU 5802 Windows 10 (贪心+dfs)
Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...
- HDU 5802 Windows 10
传送门 Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- hdu 5802 Windows 10 贪贪贪
传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...
- windows 10开启bash on windows,配置sshd,部署hadoop
1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...
- 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 ...
随机推荐
- Hibernate逍遥游记-第10章 映射继承关系-001继承关系树中的每个具体类对应一个表
1. 2. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate ...
- 2014-9-17二班----6 web project
部署 加载 到 Tomcat 6.0 服务器上 web.xml <welcome>index.jsp </welcome> <welcome&g ...
- [iOS]如何给Label或者TextView赋HTML数据
// // ViewController.m // text // // Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights ...
- 74. Search a 2D Matrix
题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the f ...
- 56. Merge Intervals
题目: Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6], ...
- HTTP Basic Authorization
在HTTP中,Basic Authorization基本认证是一种用来允许Web浏览器或其他客户端程序在请求时提供用户名和口令形式的身份凭证的一种登录验证方式. 在发送之前是以用户名追加一个冒号然后串 ...
- .NET 框架 (转载)
转载:http://www.tracefact.net/CLR-and-Framework/DotNet-Framework.aspx .NET框架 三年前写的<.NET之美>的第六章,现 ...
- redis sentinel 配置
在最小配置:master.slave各一个节点的情况下,不管是master还是slave down掉一个,“完整的”读/写功能都将受影响,这在生产环境中显然不能接受.幸好redis提供了sentine ...
- Linux系统下统计目录及其子目录文件个数
(1)查看某目录下文件的个数: ls -l |grep "^-"|wc -l 或 find ./company -type f | wc -l (2)查看某目录下文件的个数,包括子 ...
- URAL 1992
CVS Description Yoda: Visit I will the cloners on Kamino... And see this army they have created for ...