Skip to content

Commit 60395f6

Browse files
committed
AcWing 第 29 场周赛
1 parent cba0d3e commit 60395f6

File tree

6 files changed

+207
-0
lines changed

6 files changed

+207
-0
lines changed

misc/acwing/weekly/29/a/a.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
. "fmt"
5+
"io"
6+
"math"
7+
"os"
8+
)
9+
10+
// github.com/EndlessCheng/codeforces-go
11+
func run(in io.Reader, out io.Writer) {
12+
var n, t float64
13+
Fscan(in, &n, &t)
14+
Fprintf(out, "%.6f", n*math.Pow(1.00011, t))
15+
}
16+
17+
func main() { run(os.Stdin, os.Stdout) }

misc/acwing/weekly/29/a/a_test.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/acwing/weekly/29/b/b.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
"os"
8+
"sort"
9+
)
10+
11+
// github.com/EndlessCheng/codeforces-go
12+
func run(_r io.Reader, _w io.Writer) {
13+
in := bufio.NewReader(_r)
14+
out := bufio.NewWriter(_w)
15+
defer out.Flush()
16+
17+
var n, l, r, pre, cnt int
18+
Fscan(in, &n)
19+
a := make([]int, 0, n*2)
20+
for i := 0; i < n; i++ {
21+
Fscan(in, &l, &r)
22+
a = append(a, l<<1|1, (r+1)<<1) // 记录区间端点位置,用最低位表示左右
23+
}
24+
sort.Ints(a)
25+
26+
ans := make([]int, n+1)
27+
for i := 0; i < n*2; { // 扫描所有区间端点
28+
v := a[i] >> 1
29+
ans[cnt] += v - pre
30+
for ; i < n*2 && a[i]>>1 == v; i++ {
31+
cnt += a[i]&1<<1 - 1 // 左+1,右-1
32+
}
33+
pre = v
34+
}
35+
for _, c := range ans[1:] {
36+
Fprint(out, c, " ")
37+
}
38+
}
39+
40+
func main() { run(os.Stdin, os.Stdout) }

misc/acwing/weekly/29/b/b_test.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/acwing/weekly/29/c/c.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"container/heap"
6+
. "fmt"
7+
"io"
8+
"os"
9+
)
10+
11+
// github.com/EndlessCheng/codeforces-go
12+
func run(_r io.Reader, _w io.Writer) {
13+
in := bufio.NewReader(_r)
14+
out := bufio.NewWriter(_w)
15+
defer out.Flush()
16+
17+
var n, m, v, w, wt int
18+
Fscan(in, &n, &m)
19+
type edge struct{ to, wt int }
20+
g := make([][]edge, n+1)
21+
for ; m > 0; m-- {
22+
Fscan(in, &v, &w, &wt)
23+
g[v] = append(g[v], edge{w, wt})
24+
g[w] = append(g[w], edge{v, wt})
25+
}
26+
27+
const inf int = 1e18
28+
d := make([]int, n+1)
29+
for i := range d {
30+
d[i] = inf
31+
}
32+
d[1] = 0
33+
from := make([]int, n+1)
34+
h := hp{{1, 0}}
35+
for len(h) > 0 {
36+
p := heap.Pop(&h).(pair)
37+
v := p.v
38+
if d[v] < p.dis {
39+
continue
40+
}
41+
for _, e := range g[v] {
42+
w := e.to
43+
if newD := p.dis + e.wt; newD < d[w] {
44+
d[w] = newD
45+
from[w] = v
46+
heap.Push(&h, pair{w, newD})
47+
}
48+
}
49+
}
50+
51+
if d[n] == inf {
52+
Fprint(out, -1)
53+
return
54+
}
55+
56+
path := []int{}
57+
for x := n; x > 0; x = from[x] {
58+
path = append(path, x)
59+
}
60+
for i := len(path) - 1; i >= 0; i-- {
61+
Fprint(out, path[i], " ")
62+
}
63+
}
64+
65+
func main() { run(os.Stdin, os.Stdout) }
66+
67+
type pair struct{ v, dis int }
68+
type hp []pair
69+
70+
func (h hp) Len() int { return len(h) }
71+
func (h hp) Less(i, j int) bool { return h[i].dis < h[j].dis }
72+
func (h hp) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
73+
func (h *hp) Push(v interface{}) { *h = append(*h, v.(pair)) }
74+
func (h *hp) Pop() interface{} { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v }

misc/acwing/weekly/29/c/c_test.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)