hdu5802 Windows 10
来源:互联网 发布:win10电脑软件 编辑:程序博客网 时间:2024/06/06 15:37
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5802
这个题就是说从p到q,有三种操作,第一种是加法操作,每次加1,第二种操作是暂停操作,位置不变,第三种是减法操作,第一次减1,第二次减1*2,第三次1*2*2…依次增多。问从p到q最少需要多少步。
就是一个dfs贪心处理一下。
#include<stdio.h>#include<string>using namespace std;typedef long long LL;LL p,q;LL judge[40];void init(){ judge[0] = 0; for(LL i=1; i<34; i++) { LL temp = 1LL*1<<(i-(LL)1); judge[i] = temp + judge[i-1];// printf("%lld\n",judge[i]); }}LL dfs(LL x,LL step,LL stay){ if(x==q)return step; LL now = 0; while(x - judge[now] > q) now++; if(x - judge[now] == q) return step + now; LL up = q - max((LL)0,x-judge[now]); LL temp = now + max((LL)0,up - stay); return min(step + temp,dfs(x - judge[now-1],step+now,stay+1));}int main(){ int T; init(); scanf("%d",&T); while(T--) { scanf("%lld %lld",&p,&q); if(p<=q) { printf("%lld\n",q-p); } else { LL ans = dfs(p,0,0); printf("%lld\n",ans); } } return 0;}
0 0
- hdu5802 Windows 10
- hdu5802 Windows 10(贪心)
- HDU5802-Windows 10
- HDU5802 Windows 10[贪心+DFS]
- hdu5802 Windows 10(贪心搜索)
- 【HDU5802】Windows 10 (贪心 + dfs)
- 2016多校训练Contest6: 1010 Windows 10 hdu5802
- hdu5802
- 2016多校第6场1010 --hdu5802 搜索-剪枝+贪心
- windows 10
- Windows 10
- Windows 10
- Upgrade from Windows 8 to Windows 10
- [Windows 10] 体验windows10
- Windows 10 初步体验
- Windows 10 安装
- Windows 10快捷键一览
- windows 10偿鲜
- android网络编程之json传输数据以及解析方式
- dojox之gfx的基本图形
- IT技术类管理人员要考虑的事情
- java 继承
- 大数据hadoop相关属性
- hdu5802 Windows 10
- javascript之数组操作
- Sorting a Three-Valued Sequence_usaco2.1.3
- android 网络编程 HttpGet类和HttpPost类使用详解
- 指针总结
- c++数组转vector
- TCP/IP协议
- Spark内核架构
- Drupal7函数之theme_status_messages()