BottomCoder SRM 358 Div2
SRM359が存在しなかった。
また死亡。
結果
Easy(250) 243.77
Medium(500) Failed System Test
Hard(1000) Compiled
Easy
実装するだけ
Imports Microsoft.VisualBasic Imports System Imports System.Collections Imports System.Collections.Generic Imports System.Text Imports System.Math Imports Weight = System.Int32 Public Class CyclicWords Public Shared Function Cycle(ByVal a As String) As String Cycle = Mid(a, Len(a), 1) + Left(a, Len(a) - 1) End Function Public Function differentCW(ByVal words As String()) As Integer Dim i As Integer, j As Integer Dim t As New Dictionary(Of String, Integer) Dim m As String For Each k As String In words m = k For i = 0 To Len(k) If m > Cycle(k) Then m = Cycle(k) End If k = Cycle(k) Next t(m) = 1 Next differentCW = t.Count End Function End Class
Medium
全探索。100000まで検索する必要があるのと、0に注意する必要がある。
Imports Microsoft.VisualBasic Imports System Imports System.Collections Imports System.Collections.Generic Imports System.Text Imports System.Math Imports Weight = System.Int32 Public Class BrokenButtons Public Shared Function Solve(ByVal Page As Integer, ByVal Now As Integer) As Integer Return Abs(Page - Now) End Function Public Shared Function Log10C(ByVal a As Integer) As Integer If a = 0 Then Return (1) Return Int(Log10(a)) + 1 End Function Public Function minPresses(ByVal page As Integer, ByVal broken As Integer()) As Integer Dim i As Integer, j As Integer, OK As Boolean Dim Use(10) As Integer For i = 0 To 9 Use(i) = 0 Next For Each t As Integer In broken Use(t) = 1 Next minPresses = Solve(page, 100) For i = 0 To 1000000 j = i OK = True If j=0 Then If Use(j)=1 Then OK=False 'これをついか While j > 0 If Use(j Mod 10) = 1 Then OK = False End If j = j \ 10 End While If OK Then minPresses = Min(minPresses, Solve(page, i) + Int(Log10C(i))) End If Next End Function End Class
1000
DPらしいが難しい。
要復習