找回密码
 加入
搜索
楼主: pusofalse

[效率算法] 输出《傻子排序法》

 火... [复制链接]
发表于 2010-8-1 15:53:17 | 显示全部楼层
向大虾们学习了,我就纯支持下。

P版的这个《傻子排序》貌似在哪里见过。嘿嘿!!!
 楼主| 发表于 2010-8-1 15:58:02 | 显示全部楼层
回复 31# 水木子


    QQ空间吗? - -||| 祝水木子兄早日康复。
发表于 2010-8-1 16:06:46 | 显示全部楼层
回复 32# pusofalse
嘿嘿!就是、就是。

康复得差不多了吧!痒痒的,好想抠抠。
发表于 2010-8-2 00:45:44 | 显示全部楼层
正则试试~
如果是这样,估计会把傻子累死~~ O(∩_∩)O
afan 发表于 2010-8-1 14:25



    帅得一塌糊涂~~
发表于 2010-8-2 14:30:44 | 显示全部楼层
本帖最后由 3mile 于 2010-8-2 14:33 编辑

学写个另类的方案,26个字母的“傻子问题”。
本人笨,理解题经常理解到一边去。
感谢P大出题,希望P大能多出点类似的效率算法类的题。以便学习更多的思维方法。
#include <array.au3>

Local $fin
$time = TimerInit()
$str = "POQSTRZIABCDEFGHKJMLNYXWVU"
$st = StringSplit($str, "")
$number = StringLen($str)
$z = $number

While 1
If Asc($st[$z])-64<>$z Then
        $soure=$st[$z]
        _ArrayDelete($st,$z)
        _ArrayInsert($st,Asc($soure)-64,$soure)
        For $i=1 To $number
                $fin&=$st[$i]
        Next
        $fin&=","
Else
        $z-=1
        If $z=0 Then ExitLoop
EndIf
WEnd
_ArrayDisplay($st,TimerDiff($time))
MsgBox(0,TimerDiff($time),$fin)

评分

参与人数 1金钱 +40 收起 理由
pusofalse + 40 学习了!~

查看全部评分

发表于 2010-8-3 02:14:24 | 显示全部楼层
本帖最后由 psp7456 于 2010-8-3 02:16 编辑
#Include <Array.au3>
func _Main($String);$String:待处理字符串
        local $i,$j;循环下标
        local $length=stringlen($String);字符长度
        local $count=0;记录数字和所在位数均相等的数量
        local $temp;临时记录数字值
        local $num=0;记录排序次数
        Dim $pos[$length+1];定义按位记录待排序数据的数组
        
        $pos=stringsplit($String,"");将待排序数据转换成数组
        
        ConsoleWrite("["&$num&"]"&_ArrayToString($pos,",",1,$length) & @CR);初始顺序

        while $count<>$pos[0];在未完成排序前一直循环
                for $i=$length to 1 step -1 ;从最右边开始逐位判断
                        if $pos[$i]=$i then  ;如果位数和值相等,则表示排序正确
                                $count=$count+1
                        else                                ;否则要进行换位操作
                                $temp=$pos[$i]
                                for $j=$i to $pos[$i] step -1
                                        $pos[$j]=$pos[$j-1]
                                next
                                $pos[$temp]=$temp
                                $num=$num+1
                                ConsoleWrite("["&$num&"]"&_ArrayToString($pos,",",1,$length) & @CR);输入中间结果
                                ExitLoop 
                        endif
                next
        Wend
endfunc


local $begin = TimerInit()
 _Main("912345678")
ConsoleWrite("用时"&TimerDiff($begin)&"毫秒!"& @CR)
[0]9,1,2,3,4,5,6,7,8
[1]9,1,2,3,4,5,6,8,7
[2]9,1,2,3,4,5,7,6,8
[3]9,1,2,3,4,5,7,8,6
[4]9,1,2,3,4,6,5,7,8
[5]9,1,2,3,4,6,5,8,7
[6]9,1,2,3,4,6,7,5,8
[7]9,1,2,3,4,6,7,8,5
[8]9,1,2,3,5,4,6,7,8
[9]9,1,2,3,5,4,6,8,7
[10]9,1,2,3,5,4,7,6,8
[11]9,1,2,3,5,4,7,8,6
[12]9,1,2,3,5,6,4,7,8
[13]9,1,2,3,5,6,4,8,7
[14]9,1,2,3,5,6,7,4,8
[15]9,1,2,3,5,6,7,8,4
[16]9,1,2,4,3,5,6,7,8
[17]9,1,2,4,3,5,6,8,7
[18]9,1,2,4,3,5,7,6,8
[19]9,1,2,4,3,5,7,8,6
[20]9,1,2,4,3,6,5,7,8
[21]9,1,2,4,3,6,5,8,7
[22]9,1,2,4,3,6,7,5,8
[23]9,1,2,4,3,6,7,8,5
[24]9,1,2,4,5,3,6,7,8
[25]9,1,2,4,5,3,6,8,7
[26]9,1,2,4,5,3,7,6,8
[27]9,1,2,4,5,3,7,8,6
[28]9,1,2,4,5,6,3,7,8
[29]9,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,3,9,4,5,6,7,8
[225]1,2,3,9,4,5,6,8,7
[226]1,2,3,9,4,5,7,6,8
[227]1,2,3,9,4,5,7,8,6
[228]1,2,3,9,4,6,5,7,8
[229]1,2,3,9,4,6,5,8,7
[230]1,2,3,9,4,6,7,5,8
[231]1,2,3,9,4,6,7,8,5
[232]1,2,3,9,5,4,6,7,8
[233]1,2,3,9,5,4,6,8,7
[234]1,2,3,9,5,4,7,6,8
[235]1,2,3,9,5,4,7,8,6
[236]1,2,3,9,5,6,4,7,8
[237]1,2,3,9,5,6,4,8,7
[238]1,2,3,9,5,6,7,4,8
[239]1,2,3,9,5,6,7,8,4
[240]1,2,3,4,9,5,6,7,8
[241]1,2,3,4,9,5,6,8,7
[242]1,2,3,4,9,5,7,6,8
[243]1,2,3,4,9,5,7,8,6
[244]1,2,3,4,9,6,5,7,8
[245]1,2,3,4,9,6,5,8,7
[246]1,2,3,4,9,6,7,5,8
[247]1,2,3,4,9,6,7,8,5
[248]1,2,3,4,5,9,6,7,8
[249]1,2,3,4,5,9,6,8,7
[250]1,2,3,4,5,9,7,6,8
[251]1,2,3,4,5,9,7,8,6
[252]1,2,3,4,5,6,9,7,8
[253]1,2,3,4,5,6,9,8,7
[254]1,2,3,4,5,6,7,9,8
[255]1,2,3,4,5,6,7,8,9
用时28.379117278439毫秒!

评分

参与人数 1金钱 +45 收起 理由
pusofalse + 45 学习了!

查看全部评分

发表于 2010-8-3 17:12:35 | 显示全部楼层
[0]9,1,2,3,4,5,6,7,8
[1]9,1,2,3,4,5,6,8,7
[2]9,1,2,3,4,5,7,6,8
[3]9,1,2,3,4,5,7,8,6
[4]9,1,2,3,4 ...
psp7456 发表于 2010-8-3 02:14


这样写貌似高效多了,膜拜...
发表于 2010-8-7 09:49:07 | 显示全部楼层
都是高手啊,
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-25 01:38 , Processed in 0.068170 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表