找回密码
 加入
搜索
查看: 4331|回复: 4

[效率算法] [已解决]T字位选择的算法

[复制链接]
发表于 2010-7-21 10:09:54 | 显示全部楼层 |阅读模式
本帖最后由 jhun 于 2010-7-22 11:10 编辑

算了,看来这个问题无法引起达人们的兴趣啊,呵呵,只好用条办法解决,结贴

目标的位置一共二排,每排五个,最多同时出现10个,最少1个
选择目标的话以选择的点为中心,同时包含其左右及对面,也最是说一次选择最多能达四个,呈T或倒T
现在求算法,每次能尽可能的选择更多个目标
我最初的想法是根据他们的和来求最佳的选择方法,但好像很难- -
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
$Form1 = GUICreate("", 240, 125, 192, 124)
$ListView1 = GUICtrlCreateListView(" ", 0, 0, 240, 80)
GUICtrlSetStyle(-1,$LVS_ICON)
$Button1 = GUICtrlCreateButton("生成", 22, 85, 81, 33)
$Button2 = GUICtrlCreateButton("选择", 132, 85, 81, 33)
Read()
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        Read()
                Case $Button2
                        Selected()
        EndSwitch
WEnd
Func Read()
        _GUICtrlListView_DeleteAllItems ( GUICtrlGetHandle ($ListView1) )
        For $i=1 To 10
                If Random ( 1, 99 )<80 Then
                        GUICtrlCreateListViewItem( $i, $ListView1)
                Else
                        GUICtrlCreateListViewItem( "", $ListView1)
                EndIf
        Next
EndFunc
Func Selected()
        ControlListView ( "", "", "SysListView321","Select", 1)
        ControlListView ( "", "", "SysListView321","Select", 5)
        ControlListView ( "", "", "SysListView321","Select", 6)
        ControlListView ( "", "", "SysListView321","Select", 7)
        ControlFocus ( "", "", "SysListView321" )
EndFunc
发表于 2010-7-21 11:35:21 | 显示全部楼层
不知道是不是理解错了楼主的意思?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
$Form1 = GUICreate("", 240, 125, 192, 124)
$ListView1 = GUICtrlCreateListView(" ", 0, 0, 240, 80)
GUICtrlSetStyle(-1,$LVS_ICON)
;GUICtrlSetStyle(-1,BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
$Button1 = GUICtrlCreateButton("生成", 22, 85, 81, 33)
$Button2 = GUICtrlCreateButton("选择", 132, 85, 81, 33)
Read()
GUISetState()
;_GUICtrlListView_SetItemSelected($listview1,5)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        Read()
                Case $Button2
                        Selected()
                                        ;$a=$index&"|"&$index-1&"|"&$index+1&"|"&$index+5

        EndSwitch
WEnd
Func Read()
        _GUICtrlListView_DeleteAllItems ( GUICtrlGetHandle ($ListView1) )
        For $i=1 To 10
                If Random ( 1, 99 )<80 Then
                        GUICtrlCreateListViewItem( $i, $ListView1)
                Else
                        GUICtrlCreateListViewItem( "", $ListView1)
                EndIf
        Next
EndFunc
        
Func Selected()
        $index=''
        $index=_GUICtrlListView_GetSelectedIndices($ListView1)
        If $index<5 Then
        ControlListView ( "", "", "SysListView321","Select", $index)
        ControlListView ( "", "", "SysListView321","Select", $index-1)
        ControlListView ( "", "", "SysListView321","Select", $index+1)
        ControlListView ( "", "", "SysListView321","Select", $index+5)
        ControlFocus ( "", "", "SysListView321" )
        Else
        ControlListView ( "", "", "SysListView321","Select", $index)
        ControlListView ( "", "", "SysListView321","Select", $index-1)
        ControlListView ( "", "", "SysListView321","Select", $index+1)
        ControlListView ( "", "", "SysListView321","Select", $index-5)
        ControlFocus ( "", "", "SysListView321" )
        EndIf
EndFunc
 楼主| 发表于 2010-7-21 11:46:18 | 显示全部楼层
回复 2# 3mile


    你把所有的都选中了……最多只能选择四个,就是一个T字或倒T,然后由于是随机出现的,所以不可能每次都能选择四个,所以我要找的是在T字约束下尽可能的选择更多的目标

如图,这是一个标准的选择,当然,像图中就有好几种选法了,像选3也是正确的,因为3可以包含2、4和8,同样达到四个,选4、8和9同样也符合要求

像上面这图就只有4是符合的

而这图就没办法选到四个,能符合最多的只有三个,那2和7都是符合最大选择的

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2010-7-22 09:12:09 | 显示全部楼层
达人们哪去了……
发表于 2010-7-23 02:02:19 | 显示全部楼层
本帖最后由 C.L 于 2010-7-23 02:55 编辑

是不是这样:
如果有匹配T或倒T型的,记录并选中T型,如果没有T型匹配,则寻找最多匹配的数并输出匹配的数字。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>

Dim $result[10]
$Form1 = GUICreate("test", 240, 125, 192, 124)
$ListView1 = GUICtrlCreateListView(" ", 0, 0, 240, 80)
GUICtrlSetStyle(-1, $LVS_ICON)
$Button1 = GUICtrlCreateButton("生成", 22, 85, 81, 33)
$Button2 = GUICtrlCreateButton("选择", 132, 85, 81, 33)
Read()
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        Read()
                Case $Button2
                        $j = 0
                        $out = ""
                        For $i = 1 To 3
                                If $result[$i] And $result[$i + 4] And $result[$i + 5] And $result[$i + 6] Then
                                        Selected($i, $i + 4, $i + 5, $i + 6)
                                        $j+=1
                                        Sleep (1000)
                                EndIf
                                ControlListView ( "", "", "SysListView321","DeSelect", 0,9)
                                If $result[$i] And $result[$i - 1] And $result[$i + 1] And $result[$i + 5] Then
                                        Selected($i, $i - 1, $i + 1, $i + 5)
                                        $j+=1
                                        Sleep (1000)
                                EndIf
                                ControlListView ( "", "", "SysListView321","DeSelect", 0,9)
                                $temp = $result[$i] + $result[$i + 4] + $result[$i + 5] + $result[$i + 6]
                                If $temp >2 Then 
                                        If $result[$i+5] Then $out &= $i + 6 & @CRLF
                                EndIf
                                $temp = $result[$i] + $result[$i - 1] + $result[$i + 1] + $result[$i + 5]
                                If $temp >2 Then 
                                        If $result[$i] Then $out &= $i+1 &@CRLF
                                EndIf
                        Next
                        If $j Then
                                MsgBox (0,"","共有"&$j&"组匹配T型")
                        Else
                                If $out <> "" Then
                                        MsgBox (0,"","最大匹配的数是:"&@CRLF&$out)
                                Else
                                        MsgBox (0,"","没有匹配多于2个的数")
                                EndIf
                        EndIf
        EndSwitch
WEnd

Func Read()
        _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
        For $i = 1 To 10
                If Random(1, 99) < 80 Then
                        GUICtrlCreateListViewItem($i, $ListView1)
                        $result[$i - 1] = 1
                Else
                        GUICtrlCreateListViewItem("", $ListView1)
                        $result[$i - 1] = 0
                EndIf
        Next
EndFunc   ;==>Read

Func Selected($a='', $b='', $c='', $d='')
        ControlListView("", "", "SysListView321", "Select", $a)
        ControlListView("", "", "SysListView321", "Select", $b)
        ControlListView("", "", "SysListView321", "Select", $c)
        ControlListView("", "", "SysListView321", "Select", $d)
        ControlFocus("", "", "SysListView321")
EndFunc   ;==>Selected

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-11 04:46 , Processed in 0.075357 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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