Skip to content

Commit c452cd4

Browse files
committed
[1800][3A] CF1190B 博弈 石子游戏
1 parent 1d95340 commit c452cd4

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

main/1100-1199/1190B.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF1190B(_r io.Reader, out io.Writer) {
11+
in := bufio.NewReader(_r)
12+
var n, v int
13+
Fscan(in, &n)
14+
sum := int(int64(n) * int64(n-1) / 2 & 1)
15+
cnt := make(map[int]int8, n)
16+
for dup := false; n > 0; n-- {
17+
Fscan(in, &v)
18+
if cnt[v]++; cnt[v] > 1 {
19+
if dup || v == 0 || cnt[v-1] > 0 {
20+
Fprint(out, "cslnb")
21+
return
22+
}
23+
dup = true
24+
}
25+
if cnt[v+1] > 1 {
26+
Fprint(out, "cslnb")
27+
return
28+
}
29+
sum ^= v & 1
30+
}
31+
if sum == 0 {
32+
Fprint(out, "cslnb")
33+
} else {
34+
Fprint(out, "sjfnb")
35+
}
36+
}
37+
38+
//func main() { CF1190B(os.Stdin, os.Stdout) }

main/1100-1199/1190B_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/1190/B
9+
// https://codeforces.com/problemset/status/1190/problem/B
10+
func TestCF1190B(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
1
15+
0
16+
outputCopy
17+
cslnb
18+
inputCopy
19+
2
20+
1 0
21+
outputCopy
22+
cslnb
23+
inputCopy
24+
2
25+
2 2
26+
outputCopy
27+
sjfnb
28+
inputCopy
29+
3
30+
2 3 1
31+
outputCopy
32+
sjfnb
33+
inputCopy
34+
3
35+
0 0 6
36+
outputCopy
37+
cslnb
38+
inputCopy
39+
3
40+
4 5 5
41+
outputCopy
42+
cslnb`
43+
testutil.AssertEqualCase(t, rawText, 0, CF1190B)
44+
}

0 commit comments

Comments
 (0)