标题: [游戏娱乐] 批处理生成UBB彩虹代码 [打印本页]
作者: CrLf 时间: 2015-12-26 05:03 标题: 批处理生成UBB彩虹代码
本帖最后由 CrLf 于 2015-12-26 05:16 编辑
改进自:http://www.bathome.net/redirect. ... id=38720&pid=179971
优化算法,提升效率,平衡取值,并加上了详细注释
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
代码和详解:复制代码
作者: aa77dd@163.com 时间: 2015-12-26 18:04
本帖最后由 aa77dd@163.com 于 2015-12-26 18:09 编辑
我用了一个位运算选择器:
令 t 的可选值为 0 或者 -1,
~t & a | t & b
上式的值: 当 t = 0, 得 a; 否则, 得 b
这个选择器可以多层嵌套
~t & a | t & (~t1 & b | t1 & c) 以此类推
这样多层嵌套后, 就可以实现在小范围内索引区间搜索, 最开始我也想用 for + if 的方式实现, 然后又觉得效率不高, 特别是批处理的 for 代码在退出前 都不能 break
但 set /a 构造 的这种多层嵌套选择器 是否 比 for + if 效率要高, 也只是我想当然, 实际上我并没有测试比较过
以下示例 在 5 个数中找出 不大于 x 的最大的一个数- @echo off
- setlocal enableDelayedExpansion
-
- set "@1=18225"
- set "@2=17956"
- set "@3=17689"
- set "@4=17424"
- set "@5=17161"
-
- set "exp=0"
- for /L %%i in (5 -1 1) do (
- set "exp=t=x-@%%i>>31,~t&@%%i|t&(!exp!)"
- )
- set exp
-
- set /a "x=17688,result=(%exp%)"
- set result
-
- pause
-
- exit
复制代码
作者: CrLf 时间: 2015-12-26 20:30
本帖最后由 CrLf 于 2015-12-26 21:28 编辑
回复 2# aa77dd@163.com
位运算是不错,应该比 if 快
再优化一下,!(@%%i/t) 仔细想一想还是减法配合 >> 更快
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |