京东笔试(凉)
请不吝指教
1、给6个面板的长宽,判断是否能构乘长方体?
似乎很简单???55%
thx@HelloJAVA123,正确方式应该以面{a,b}且a<=b方式记录并考虑面拼接
package main import "fmt" func main() { var T, H, W int fmt.Scan(&T) for i := 1; i <= T; i++ { m := make(map[int]int) kind := 0 for j := 1; j <= 6; j++ { fmt.Scan(&H, &W) if _, f := m[H]; !f { kind++ } if _, f := m[W]; !f { kind++ } m[H]++ m[W]++ } ans := "POSSIBLE" if kind > 3 { ans = "IMPOSSIBLE" } else { if kind == 3 { for _, v := range m { if v != 4 { ans = "IMPOSSIBLE" } } } else if kind == 2 { for _, v := range m { if v != 4 || v != 8 { ans = "IMPOSSIBLE" } } } } fmt.Println(ans) } }
2、n个编号,a[i]表示编号i可跳的步长,从1号编号开始跳,初始可跳h0步或a[1]步,到达编号i时可跳的步长为{跳到i时的步长 or a[i]},不可跳过n,求跳到n时路径数?对998244353取模
22%。
package main import "fmt" /* step[i][j]: 在第i个格子时,步长是否可以为j dp[i]: 到达第i个格子经过的路径数,有dp[i] = sum{dp[k]}, if k canReach, 0<=k<i */ const maxn = 1005 const p = 998244353 func main() { dp := [maxn]int{} step := [maxn][maxn]bool{} a := [maxn]int{} n, h := 0, 0 fmt.Scan(&n, &h) for i := 1; i <= n; i++ { fmt.Scan(&a[i]) } step[1][h], step[1][a[1]] = true, true dp[1] = 1 for i := 2; i <= n; i++ { step[i][a[i]] = true for j := 1; j < i; j++ { if step[j][i-j] { dp[i] = (dp[i]+dp[j])%p step[i][i-j] = true } } //fmt.Println(dp[i]) } fmt.Println(dp[n]) }#京东##笔试题目#