AtCoder Beginner Contest 187のメモ
前置き
Atcoderをやってみたので、自分用のメモです。
あとから加筆・修正する予定です。
問題
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
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)
}
}
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
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")
}
}
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
覚えてたら後で書きます。
F
覚えてたら後で書きます。
Author And Source
この問題について(AtCoder Beginner Contest 187のメモ), 我々は、より多くの情報をここで見つけました https://qiita.com/nogawanogawa/items/1bd798d490766086d72d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .