Skip to content

Commit 8fe2d5f

Browse files
committed
[1800][坑] CF978B 构造 结论
1 parent d903c1d commit 8fe2d5f

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

main/900-999/979B.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF979B(_r io.Reader, out io.Writer) {
11+
in := bufio.NewReader(_r)
12+
var k, ans, ansI, cntAns int
13+
var s string
14+
Fscan(in, &k)
15+
for i := 0; i < 3; i++ {
16+
Fscan(in, &s)
17+
n := len(s)
18+
c := ['z' + 1]int{}
19+
for _, b := range s {
20+
c[b]++
21+
}
22+
mx := 0
23+
if c[s[0]] < n {
24+
for _, c := range c {
25+
if c > mx {
26+
mx = c
27+
}
28+
}
29+
if mx+k < n {
30+
mx += k
31+
} else {
32+
mx = n
33+
}
34+
} else if k == 1 && n > 1 {
35+
mx = n - 1
36+
} else {
37+
mx = n
38+
}
39+
if mx > ans {
40+
ans, ansI, cntAns = mx, i, 1
41+
} else if mx == ans {
42+
cntAns++
43+
}
44+
}
45+
if cntAns > 1 {
46+
Fprint(out, "Draw")
47+
} else {
48+
Fprint(out, []string{"Kuro", "Shiro", "Katie"}[ansI])
49+
}
50+
}
51+
52+
//func main() { CF979B(os.Stdin, os.Stdout) }

main/900-999/979B_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/979/B
9+
// https://codeforces.com/problemset/status/979/problem/B
10+
func TestCF979B(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
3
15+
Kuroo
16+
Shiro
17+
Katie
18+
outputCopy
19+
Kuro
20+
inputCopy
21+
7
22+
treasurehunt
23+
threefriends
24+
hiCodeforces
25+
outputCopy
26+
Shiro
27+
inputCopy
28+
1
29+
abcabc
30+
cbabac
31+
ababca
32+
outputCopy
33+
Katie
34+
inputCopy
35+
15
36+
foPaErcvJ
37+
mZaxowpbt
38+
mkuOlaHRE
39+
outputCopy
40+
Draw
41+
inputCopy
42+
60
43+
ddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb
44+
dcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY
45+
XaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ
46+
outputCopy
47+
Draw`
48+
testutil.AssertEqualCase(t, rawText, -1, CF979B)
49+
}

0 commit comments

Comments
 (0)