I tried Atcoder, so it's a memo for myself. I plan to add and correct it later.
https://atcoder.jp/contests/abc187
A
Q_A.go
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
var A, B string
fmt.Scanf("%s %s", &A, &B)
A_ := strings.Split(A, "")
B_ := strings.Split(B, "")
a_1, _ := strconv.Atoi(A_[0])
a_2, _ := strconv.Atoi(A_[1])
a_3, _ := strconv.Atoi(A_[2])
a := a_1 + a_2 + a_3
b_1, _ := strconv.Atoi(B_[0])
b_2, _ := strconv.Atoi(B_[1])
b_3, _ := strconv.Atoi(B_[2])
b := b_1 + b_2 + b_3
if a > b{
fmt.Printf("%d\n", a)
} else {
fmt.Printf("%d\n", b)
}
}
B
Q_B.go
package main
import (
"fmt"
)
func main() {
var N int
fmt.Scanf("%d", &N)
x := make([]int, N)
y := make([]int, N)
for i:=0; i<N; i++{
fmt.Scanf("%d %d", &x[i], &y[i])
}
var count int = 0
for i:=0; i<N-1; i++{
for j:=i+1; j<N; j++{
r := float32(y[j] - y[i]) / float32(x[j] - x[i])
if r * r <= 1 {
count ++
}
}
}
fmt.Printf("%d\n", count)
}
C
Q_C.go
package main
import (
"fmt"
"strings"
)
func main() {
var N int
fmt.Scanf("%d", &N)
S_a := make(map[string]int, N)
S_b := make(map[string]int, N)
var tmp string
var ans string = ""
for i:=0; i<N; i++{
fmt.Scanf("%s", &tmp)
t := strings.Split(tmp, "")
if t[0] == "!"{
S_b[tmp[1:]] = 1
if _, ok := S_a[tmp[1:]]; ok {
ans = tmp[1:]
}
} else {
S_a[tmp] = 1
if _, ok := S_b[tmp]; ok {
ans = tmp
}
}
}
if ans != ""{
fmt.Printf("%s\n", ans)
} else {
fmt.Printf("satisfiable\n")
}
}
D
Q_D.go
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
type toh struct {
a, t int
}
var r = bufio.NewReader(os.Stdin)
func main() {
var n int
fmt.Fscan(r, &n)
ao := 0
ar := make([]toh, n)
for i := range ar {
var a, b int
fmt.Fscan(r, &a, &b)
ao += a
ar[i].a = a
ar[i].t = b
}
sort.Slice(ar, func(i, j int) bool {
return ar[i].a+ar[i].t+ar[i].a < ar[j].a+ar[j].t+ar[j].a
})
ans := 0
t := 0
for i := n - 1; i >= 0; i-- {
ao -= ar[i].a
t += ar[i].a + ar[i].t
ans++
if ao < t {
fmt.Println(ans)
return
}
}
}
E If you remember, I will write it later.
F If you remember, I will write it later.
Recommended Posts