多校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 ...
随机推荐
- 利用Nginx搭建http和rtmp协议的流媒体服务器
http://www.linuxidc.com/Linux/2013-02/79118.htm
- 修改MDI工程主框架窗口标题(修改CREATESTRUCT结构体)
版权声明:本文为博主原创文章,未经博主允许不得转载. //在CMainFrame类的PreCreateWindow函数中加入 m_strTitle = _T("Hello"); c ...
- Maven Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean Failed to delete access_log
I'm trying to run simple struts project using maven and tomcat. When I'm trying to exucute next goal ...
- SSH公钥认证登录
概述: SSH登录的认证方式分为两种,一种是使用用户名密码的方式,另一种就是通过公钥认证的方式进行访问, 用户名密码登录的方式没什么好说的,本文主要介绍通过公钥认证的方式进行登录. 思路: 在客户端生 ...
- rundeck email配置文件配置
最近工作中用到了一个任务管理软件rundeck,其中有个很重要的功能就是任务执行提醒,用邮件执行,其中一些配置项,官网没有详细的说明,在网上也没有一个整体的说明,在次跟大家共享下,rundeck的使用 ...
- jquery在线教程
http://www.runoob.com/jquery/jquery-slide.htmlhttp://www.w3school.com.cn/jquery/http://www.phpstudy. ...
- hdu 4901 The Romantic Hero (dp)
题目链接 题意:给一个数组a,从中选择一些元素,构成两个数组s, t,使s数组里的所有元素异或 等于 t数组里的所有元素 位于,求有多少种构成方式.要求s数组里 的所有的元素的下标 小于 t数组里的所 ...
- UVa 11754 (中国剩余定理 枚举) Code Feat
如果直接枚举的话,枚举量为k1 * k2 *...* kc 根据枚举量的不同,有两种解法. 枚举量不是太大的话,比如不超过1e4,可以枚举每个集合中的余数Yi,然后用中国剩余定理求解.解的个数不够S个 ...
- POJ 1577 Falling Leaves
题意:给出一些字符串,从上到下的建树,输出其前序遍历 像前面那一题一样,先建树,然后再递归前序遍历 不过想像上一题那样用数组建树,建树和上题一样的办法,可是应该怎么输出前序遍历呢= = 还是看的题解= ...
- Windows SDK 实现不规则窗口介绍
不规则窗口在程序界面设计中能提供非常好的用户体验,以下是我程序运行时的效果图: 以下是代码,注意需要修改一些简单的位置,如资源ID,项目的头文件等,这些是根据你创建的win32程序的项目名改变的,我的 ...