2019年1月25日 星期五

0125練習 uva11470

0125資料夾


UVA 11470題目

題意: N x N 方陣,最多10x10,算每一圈的數字和

vb版 解題參考,輸入 in.txt  輸出out.txt


https://uva.onlinejudge.org/external/114/11470.pdf
Public Class Form1
    Dim a(10, 10) As Integer '最多 10x10
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Hide()
        FileOpen(1, "in.txt", OpenMode.Input)
        FileOpen(3, "out.txt", OpenMode.Output)
        For fn = 1 To 1
            'If fn = 2 Then PrintLine(3)
            Do While True
                Dim n% = LineInput(fn)
                If n = 0 Then Exit Do
                For i = 0 To n - 1
                    Dim s = LineInput(fn)
                    Dim dat() = s.Split(" ")
                    For j = 0 To n - 1
                        a(i, j) = dat(j)
                    Next
                Next
                PrintLine(3, fxx(n))
            Loop
        Next
        End
    End Sub
    Dim dr() = {0, 1, 0, -1}
    Dim dc() = {1, 0, -1, 0}
    '       d 0 1 2 3
    Function fxx(ByVal n As Integer) As String
        If (n = 1) Then Return a(0, 0)
        fxx = ""
        Dim m = (n + 1) \ 2  '共幾圈
        Dim r, c, sum, k As Integer
        For i = 0 To m - 1 ' i
            sum = 0 : r = i : c = i
            k = n - 1 - 2 * i '每個方向幾個數字
            If k = 0 Then sum = a(r, c)
            For d = 0 To 3 '四個方向
                For j = 1 To k '每個方向幾個數字
                    r += dr(d) : c += dc(d) '下一個位置座標
                    sum += a(r, c)
                Next j
            Next d
            If i > 0 Then fxx &= " "
            fxx &= sum
        Next i
    End Function
End Class
 

Related Posts:

  • 0125練習 uva114700125資料夾 UVA 11470題目 題意: N x N 方陣,最多10x10,算每一圈的數字和 vb版 解題參考,輸入 in.txt  輸出out.txt https://uva.onlinejudge.org/external/114/11470.pdf … Read More
  • To Z2A 2019vb_m6104模擬參考+104正式參考… Read More
  • 篩法、陣列的應用篩法400.xlsx 找 2~n(<10^7)的所有質數 虛擬碼 動態陣列 p 、靜態陣列 c(n) 初值 false設為質數、true被刪記(非質數) push (2) for i= 3 ~ n jump 2   if not c(i) then   &nbs… Read More
  • 1129C++ c/c++研習資料夾 #include <iostream> using namespace std; int p[ 100 ]; int pcnt; bool isp(int x) {      int i;  //  &… Read More
  • 資2忠 連連看教學版範例         指導:陳俊華 2018/12/12… Read More

0 意見:

張貼留言