I tried Atcoder, so it's a memo for myself. I plan to add and correct it later.
https://atcoder.jp/contests/abc184
A
Q_A.go
package main
import (
"fmt"
)
func main() {
var a, b, c, d int
fmt.Scanf("%d %d", &a, &b)
fmt.Scanf("%d %d", &c, &d)
ans := a * d - b * c
fmt.Printf("%d\n", ans)
}
B
Q_B.go
package main
import (
"fmt"
"strings"
)
func main() {
var N, X int
fmt.Scanf("%d %d", &N, &X)
var S string
fmt.Scanf("%s", &S)
result := strings.Split(S, "")
for i:=0; i<N; i++{
if result[i] == "o"{
X += 1
} else if X > 0{
X -= 1
}
}
fmt.Printf("%d\n", X)
}
C
Q_C.go
package main
import (
"fmt"
"math"
)
func main() {
var r1, r2, c1, c2 int
fmt.Scanf("%d %d", &r1, &c1)
fmt.Scanf("%d %d", &r2, &c2)
var ans int
if (r1 == r2) && (c1 == c2){
ans = 0
} else if (r1+c1 == r2+c2) || (r1-c1 == r2-c2) || math.Abs(float64(r1-r2)) + math.Abs(float64(c1-c2)) <=3{
ans = 1
} else if ((r2 - r1 + c2 - c1) % 2 == 0) || (math.Abs(float64(r2 - r1 - c2 + c1)) <= 3) || (math.Abs(float64(r2 - r1 + c2 - c1)) <= 3){
ans = 2
} else {
ans = 3
}
fmt.Printf("%d\n", ans)
}
D
Q_D.go
package main
import (
"fmt"
)
var dp [101][101][101]float64
//Recursive function that returns the expected value of the move
func f(a int, b int, c int) float64{
//If you have already calculated
if dp[a][b][c] != 0{
return dp[a][b][c]
}
//If you have reached the goal, the expected value of movement is 0
if (a == 100) || (b == 100) || (c == 100) {
return 0
}
var ans float64 = 0
ans += (f(a+1, b, c) + 1) * float64(a) / float64(a + b + c)
ans += (f(a, b+1, c) + 1) * float64(b) / float64(a + b + c)
ans += (f(a, b, c+1) + 1) * float64(c) / float64(a + b + c)
dp[a][b][c] = ans
return ans
}
func main() {
var A, B, C int
fmt.Scanf("%d %d %d", &A, &B, &C)
fmt.Printf("%f\n", f(A, B, C))
}
E If you remember, I will write it later.
F If you remember, I will write it later.
Recommended Posts