jzoj P2190 dis
来源:互联网 发布:mac帧ip类型数据长度 编辑:程序博客网 时间:2024/06/07 13:22
题目大意:
给出两个数a; b,每次操作可以把a + 1 或把a * 2
问至少多少次操作可以使得a = b
数据范围限制
• 对于30% 的数据,1 <= a <= b <= 100。
• 对于60% 的数据,1 <= a <= b <= 10^6。
• 对于100% 的数据,1 <= a <= b <= 10^9。
题解:
贪心+模拟:
我们可以通过B倒推到A,我们可以发现,每次如果B 可以 /2,即b mod 2=0那么/2很明显比-1 更优,然后模拟即可。注意判断B/2>=A
var i,ans,a,b:longint;begin assign(input,'dis.in'); reset(input); assign(output,'dis.out');rewrite(output); readln(a,b); ans:=0; while a<>b do begin inc(ans); if (b mod 2=0) and (b div 2>=a) then b:=b div 2 else b:=b-1; end; writeln(ans); close(input); close(output);end.
阅读全文
1 0
- jzoj P2190 dis
- 【SDOI2008】【BZOJ】【P2190】【仪仗队】【题解】
- 优化dis
- onToch dis
- short dis
- Dis# v3.1.1
- crash dis command
- dlut1219-spfa+二维dis
- HDU 5748 Bellovin [DIS]
- Cobra —— super dis
- API GetCurrentTime Let dis cd1
- Dis# v3.1.2 by MegaX
- Dis# v3.1.4 by MegaX
- {En/Dis}able IPv6 function
- python分析字节码dis
- Python dis 模块初步使用
- DIS与DR对比表
- re-dis 操-作-配-置
- c++基础之随机函数
- 用ImageLoader查找图片继承Application
- unigui导出EXCEL使用NATIVEEXCEL
- 花式读取Android CPU使用率
- 2017 ACM/ICPC Asia Regional Shenyang Online 1004 array array array
- jzoj P2190 dis
- ImageLoader
- opencv中标定函数calibrateCamera
- Android4.2.2编译笔记:从Ubuntu环境开始
- 铁轨,紫书P140UVa514
- TP框架的使用(ThinkPHP3.2.2)
- shell脚本连接、读写、操作mysql数据库实例
- XRecyclerView 上拉刷新、下拉加载
- golang -strconv包常用函数笔记