头像

Minions


访客:2507

离线:11个月前



Minions
11个月前
package main

import (
    "fmt"    
)

func quickSort(arr []int) []int {
    if len(arr) <= 1 {
        return arr
    }

    var left, right []int
    pivot := arr[0]
    for _, x := range arr[1:] {
        if x < pivot {
            left = append(left, x)
        } else {
            right = append(right, x)
        }
    }

    return append(quickSort(left), append([]int{pivot}, quickSort(right)...)...)
}

func main() {
    var N int
    fmt.Scanf("%d\n", &N)

    arr := make([]int, N)
    for i := 0; i < N; i++ {
        fmt.Scanf("%d", &arr[i])
    }

    arr = quickSort(arr)
    for _, x := range arr {
        fmt.Print(x, " ")
    }
}





Minions
2019-04-15 04:53
package main

import (
    "fmt"
)

func main() {
    var N int
    fmt.Scanf("%d", &N)

    coins := []int{64, 16, 4, 1}
    res := 0
    N = 1024 - N
    for _, v := range coins {
        res += N/v
        N %= v
    }

    fmt.Print(res)
}



Minions
2019-02-02 03:30

Go 代码

package main

import (
    "fmt"    
)

func main() {
    var N,V int
    fmt.Scanf("%d %d\n", &N, &V)
    var dp [][]int
    for i := 0; i < N+1; i++ {
        arr := make([]int, V+1)
        dp = append(dp, arr)
    }

    v := make([]int, N)
    w := make([]int, N)

    for i := 0; i < N; i++ {
        fmt.Scanf("%d %d\n", &v[i], &w[i])
    }

    for i := 1; i <= N; i++ {
        for j := 1; j <= V; j++ {
            if j >= v[i-1] {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-v[i-1]]+w[i-1])
            } else {
                dp[i][j] = dp[i-1][j]
            }
        }
    }

    fmt.Println(dp[N][V])
}

func max(a,b int) int {
    if a > b {
        return a
    } 
    return b
}