Skip to content

Commit 5a18180

Browse files
committed
CF570B 数形结合
1 parent 5378968 commit 5a18180

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

main/500-599/570B.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
. "fmt"
5+
"io"
6+
)
7+
8+
// github.com/EndlessCheng/codeforces-go
9+
func CF570B(in io.Reader, out io.Writer) {
10+
var n, m int
11+
Fscan(in, &n, &m)
12+
if n == 1 && m == 1 {
13+
Fprint(out, 1)
14+
} else if m*2 > n {
15+
Fprint(out, m-1)
16+
} else {
17+
Fprint(out, m+1)
18+
}
19+
}
20+
21+
//func main() { CF570B(os.Stdin, os.Stdout) }

main/500-599/570B_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/570/B
9+
// https://codeforces.com/problemset/status/570/problem/B
10+
func TestCF570B(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
3 1
15+
outputCopy
16+
2
17+
inputCopy
18+
4 3
19+
outputCopy
20+
2`
21+
testutil.AssertEqualCase(t, rawText, 0, CF570B)
22+
}

0 commit comments

Comments
 (0)