- 投稿日:2021-02-27T23:09:21+09:00
AtCoder Beginner Contest 193のメモ
前置き
Atcoderをやってみたので、自分用のメモです。
あとから加筆・修正する予定です。問題
A
Q_A.gopackage main import ( "fmt" ) func main() { var A, B float32 fmt.Scanf("%f %f", &A, &B) wariai := (A-B)/A *100 fmt.Printf("%f\n", wariai) }B
Q_B.gopackage main import ( "bufio" "fmt" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) func nextInt() int { sc.Scan() i, e := strconv.ParseInt(sc.Text(),10,32) if e != nil { panic(e) } return int(i) } func main() { sc.Split(bufio.ScanWords) var N int fmt.Scanf("%d",&N) var min_p int = -1 var A, P, X int for i:=0; i<N; i++{ A = nextInt() P = nextInt() X = nextInt() if (A < X) && (min_p < 0){ min_p = P } else if (A < X) && (P < min_p){ min_p = P } } fmt.Printf("%d\n", min_p) }C
Q_C.gopackage main import ( "fmt" ) func main() { var N int64 fmt.Scanf("%d", &N) var i, v int64 m := make(map[int64]int) for i=2; i*i<=N; i++{ v = i for j:=0; ; j++{ v = v * i if v <= N{ _, isThere := m[v] if !isThere { m[v] = 1 } } else { break } } } result := N - int64(len(m)) fmt.Printf("%d\n", result) }D
Q_D.gopackage main import ( "fmt" "strings" "strconv" ) func score(s []int) int{ hand := make(map[int]int) for i:=0; i<5; i++{ _, isThere := hand[s[i]] if !isThere { hand[s[i]] = 1 } else { hand[s[i]] = hand[s[i]] + 1 } } var sc int = 0 for i:=1; i<10; i++{ _, isThere := hand[i] var r int = 1 if isThere { for j:=0; j<hand[i]; j++{ r = r * 10 } sc += i * r }else { sc += i } } return sc } func prob(m map[int]int,K int, s int , t int) float64 { var p float64 if s == t { bunshi := m[s] bunshi *= m[s] -1 bunbo := (9*K-8) * (9*K-9) p = float64(bunshi) / float64(bunbo) } else { bunshi := m[s] bunshi *= m[t] bunbo := (9*K-8) * (9*K-9) p = float64(bunshi) / float64(bunbo) } return p } func main() { var K int var S, T string fmt.Scanf("%d", &K) fmt.Scanf("%s", &S) fmt.Scanf("%s", &T) m := make(map[int]int) for i:=1; i<10; i++{ m[i] = K } S_fact := strings.Split(S, "") T_fact := strings.Split(T, "") for i:=0; i<4; i++{ n, _ := strconv.Atoi(S_fact[i]) m[n] = m[n] - 1 l, _ := strconv.Atoi(T_fact[i]) m[l] = m[l] - 1 } var result float64 = 0 for i:=1; i<10; i++{ for j:=1; j<10; j++{ p := prob(m, K, i, j) var s []int for k:=0; k<4; k++{ tmp, _ := strconv.Atoi(S_fact[k]) s = append(s, tmp) } s = append(s, i) score_s := score(s) var t []int for k:=0; k<4; k++{ tmp, _ := strconv.Atoi(T_fact[k]) t = append(t, tmp) } t = append(t, j) score_t := score(t) if score_s > score_t { result += p } } } fmt.Printf("%f\n", result) }E
覚えてたら後で書きます。
F
覚えてたら後で書きます。
- 投稿日:2021-02-27T11:06:23+09:00
go get で "module declares its path as" のようなエラー
エラー
$ go get github.com/motemen/ghq go get: github.com/motemen/ghq@v1.0.3 updating to github.com/motemen/ghq@v1.1.6: parsing go.mod: module declares its path as: github.com/x-motemen/ghq but was required as: github.com/motemen/ghq
解決策
$ go get github.com/x-motemen/ghq
なぜ
motemen さんが x-motemen さんに改名した?