Skip to content

Commit 7ad0886

Browse files
committed
[2000] CF1567D 贪心+构造
1 parent 445a214 commit 7ad0886

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

main/1500-1599/1567D.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
"math"
8+
"strconv"
9+
)
10+
11+
// github.com/EndlessCheng/codeforces-go
12+
func CF1567D(in io.Reader, _w io.Writer) {
13+
out := bufio.NewWriter(_w)
14+
defer out.Flush()
15+
var T, s, n int
16+
for Fscan(in, &T); T > 0; T-- {
17+
Fscan(in, &s, &n)
18+
x := int(math.Pow10(len(strconv.Itoa(s)) - 1))
19+
for i := 1; i < n; i++ {
20+
for s-x < n-i {
21+
x /= 10
22+
}
23+
Fprint(out, x, " ")
24+
s -= x
25+
}
26+
Fprintln(out, s)
27+
}
28+
}
29+
30+
//func main() { CF1567D(os.Stdin, os.Stdout) }

main/1500-1599/1567D_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/1567/D
9+
// https://codeforces.com/problemset/status/1567/problem/D
10+
func TestCF1567D(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
6
15+
97 2
16+
17 1
17+
111 4
18+
100 2
19+
10 9
20+
999999 3
21+
outputCopy
22+
70 27
23+
17
24+
3 4 100 4
25+
10 90
26+
1 1 2 1 1 1 1 1 1
27+
999900 90 9`
28+
testutil.AssertEqualCase(t, rawText, 0, CF1567D)
29+
}

0 commit comments

Comments
 (0)