hdu5802 Windows 10(贪心)
来源:互联网 发布:java统计页面访问量 编辑:程序博客网 时间:2024/06/06 04:36
hdu5802
题目
就是要求调到目标音量的最小步数,如果向上调的话每次只能一步,向下的话,如果上一次也是像下,这次是上次的*2,如果停顿或者向上的话就是1步。
思路
朴素的bfs会超时,应该是贪心,以尽快的逼近目标位置为目的,同时注意,向上走和停顿是可以合并的,最后向上赶的步数可以抵消掉之前下降过程中停顿的次数,细节看代码。
代码
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>using namespace std;typedef long long ll;ll n,m;ll dfs(int p,int q,int step,int res){ int x=0; if(p==q) return step; while(p-(1LL<<x)+1>q) x++; if(p-(1LL<<x)+1==q) return step+x; ll up=q-max(0LL,p-(1LL<<x)+1); ll temp=max(0LL,up-res); return min(x+temp+step,dfs(p-(1LL<<(x-1))+1,q,step+x,res+1));}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%I64d %I64d",&n,&m); if(n<=m) { printf("%I64d\n",m-n); } else printf("%I64d\n",dfs(n,m,0,0)); } return 0;}
0 0
- hdu5802 Windows 10(贪心)
- HDU5802 Windows 10[贪心+DFS]
- hdu5802 Windows 10(贪心搜索)
- 【HDU5802】Windows 10 (贪心 + dfs)
- hdu5802 Windows 10
- HDU5802-Windows 10
- 2016多校训练Contest6: 1010 Windows 10 hdu5802
- hdu5802
- 2016多校第6场1010 --hdu5802 搜索-剪枝+贪心
- hdu 5802 Windows 10 (贪心)
- HDU 5802 Windows 10【贪心】
- HDU 5802 Windows 10 (贪心)
- hdu 5802 Windows 10 (贪心+dfs)
- hdu 5802 Windows 10 (贪心 + 思维)
- HDU-5802-Windows 10-贪心+dfs
- HDU 5802 Windows 10(贪心+DFS)
- 【HDOJ5802】Windows 10 (贪心 + dfs)
- HDU-5802-Windows 10(DFS+贪心)
- 微信开发 遇到 config:invalid url domain
- angularJS的路由配置——转
- android studio导出jar包
- Web前端开发规范:HTML书写规范
- android图片涂鸦,具有设置画笔,撤销,缩放移动等功能(一)
- hdu5802 Windows 10(贪心)
- Socket基础知识(一)
- LinkedList源码详解
- qduoj LC的课后辅导
- adt-bundlee-windows-x86-x64之安卓开发环境一键打包下载
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- spoj694 Distinct Substrings
- 接口
- BZOJ 1059 [ZJOI2007]矩阵游戏