English 中文(简体)
Algorithm 过滤重复信函和调往现有信菜单
原标题:Algorithm for filtering out duplicate letters and reassignment to available letters for menu alt keys
  • 时间:2011-11-22 05:53:39
  •  标签:
  • c#
  • algorithm

我的温树申请有许多菜单,每个菜单平均有30个菜单。 在任何特定的菜单中,从同一封信起可以有多个字。

目前,我采用一种简单的方法,通过预先安排每个菜单和按每个菜单项目分类,为每个项目绘制一个带的关键地图。

我需要能够发现重复的关键绘图(启动信函),并把它重新定位为另一种特征;现在还没有这样做。 获胜的特性是尽可能接近尾声的。

MENU Example

  • List item
  • New Window
  • Save Document
  • Print
  • Print Preview

更理想的算法将足以在扼杀词中研究下一个词,并具有补充规则。 如果我能制定一整套规则,如:

“FireFoxMenu”</p

我理解,火ox最有可能人工分配其地图,但我正试图以建设性的方式 la。

最佳回答

由于你平均拥有30件物品,总是会收到不止一次使用的加速信。 您当然希望有一个项目来改变您的方案的多重运行(或更糟糕的是,同一行程中的多重用途)。

为什么不简单地保留,要求每个菜单都有固定的加速信片财产?

问题回答

与我一样,对于patient来说,在C# here上对匈牙利 a进行了非常清洁的执行,这里是解决欧佩斯问题的快速测试设备:

Module Module1

Sub Main()
    test1()
End Sub

Sub test1()
    Dim menus() As String =
    {"File",
     "Fiddle",
     "Forest",
     "Fangle",
     "Edit",
     "Entity",
     "Entropy",
     "Eviction",
     "View",
     "Vixen",
     "Visible",
     "Window",
     "Wait",
     "What",
     "Tools",
     "Time",
     "Total",
     "Tea"}
    Dim items As Integer = menus.GetUpperBound(0)
    Dim alphabet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    Dim letters As Integer = alphabet.Length - 1
    Dim costs(items, letters) As Integer
    Dim cost As Integer
    Dim ch As String
    Dim o As Integer
    Dim longest As Integer = 0
    For i = 0 To items
        cost = 1
        If menus(i).Length > longest Then
            longest = menus(i).Length
        End If
        For j = 0 To menus(i).Length - 1
            ch = menus(i).Substring(j, 1)
            o = alphabet.IndexOf(ch, StringComparison.InvariantCultureIgnoreCase)
            If costs(i, o) = 0 Then   Don t overwrite when same letter more than once in word  
                costs(i, o) = cost
                cost += 2
            End If
        Next
        For j = 0 To letters
            If costs(i, j) = 0 Then
                costs(i, j) = 99
            End If
        Next
    Next
    longest += 1
    For r = 1 To 2
        Console.Write("".PadRight(longest))
        For i = 0 To letters
            Console.Write(alphabet.Substring(i, 1).PadLeft(3))
        Next
        Console.WriteLine("")
        For i = 0 To items
            Console.Write(menus(i).PadRight(longest))
            For j = 0 To letters
                Console.Write(costs(i, j).ToString.PadLeft(3))
            Next
            Console.WriteLine("")
        Next
        If r = 1 Then
            Dim h As New HungarianAlgorithm
            Dim result() As Integer
            result = h.FindAssignments(costs)
            Console.WriteLine("Answer:")
            For i = 0 To items
                Console.WriteLine(menus(i).PadRight(longest) & alphabet.Substring(result(i), 1))
            Next
        End If
    Next r
End Sub

End Module





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签