Skip to content

Commit c5a67bd

Browse files
committed
fix runners
1 parent 44e09e3 commit c5a67bd

File tree

24 files changed

+538
-168
lines changed

24 files changed

+538
-168
lines changed

algorithms/data-structures/fibonacci-heap/scala/FibonacciHeap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.collection.mutable.ArrayBuffer
33

44
object FibonacciHeap {
55
def fibonacciHeap(operations: Array[Int]): Array[Int] = {
6-
val heap = mutable.PriorityQueue.empty[Int](Ordering[Int].reverse)
6+
val heap = mutable.PriorityQueue.empty[Int](using Ordering.Int.reverse)
77
val results = ArrayBuffer[Int]()
88
for (op <- operations) {
99
if (op == 0) {

algorithms/dynamic-programming/convex-hull-trick/csharp/ConvexHullTrick.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public static long[] Solve(long[][] lines, long[] queries)
4141
return results;
4242
}
4343

44+
public static long[] Solve(int[][] lines, int[] queries)
45+
{
46+
long[][] longLines = lines
47+
.Select(line => line.Select(value => (long)value).ToArray())
48+
.ToArray();
49+
long[] longQueries = queries.Select(value => (long)value).ToArray();
50+
return Solve(longLines, longQueries);
51+
}
52+
4453
public static void Main(string[] args)
4554
{
4655
var tokens = Console.ReadLine().Trim().Split();

algorithms/dynamic-programming/fibonacci/csharp/Fibonacci.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ public class Fibonacci
33
{
44
public int cal(int number)
55
{
6-
int a = 1, b = 0, temp;
7-
while (number >= 0){
8-
temp = a;
9-
a = a + b;
6+
if (number <= 0)
7+
{
8+
return 0;
9+
}
10+
11+
int a = 0, b = 1;
12+
for (int i = 1; i < number; i++)
13+
{
14+
int temp = a + b;
15+
a = b;
1016
b = temp;
11-
number--;
1217
}
18+
1319
return b;
14-
}
20+
}
1521
}

algorithms/geometry/convex-hull-jarvis/scala/ConvexHullJarvis.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ object ConvexHullJarvis {
2121

2222
var hullCount = 0
2323
var current = start
24-
do {
24+
var firstPass = true
25+
while (firstPass || current != start) {
26+
firstPass = false
2527
hullCount += 1
2628
var candidate = 0
2729
for (i <- 1 until n) {
@@ -37,7 +39,7 @@ object ConvexHullJarvis {
3739
}
3840
}
3941
current = candidate
40-
} while (current != start)
42+
}
4143

4244
hullCount
4345
}

algorithms/geometry/delaunay-triangulation/scala/DelaunayTriangulation.scala

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,36 @@ object DelaunayTriangulation {
44
val n = arr(0)
55
if (n < 3) return 0
66

7-
val px = Array.tabulate(n)(i => arr(1 + 2 * i).toDouble)
8-
val py = Array.tabulate(n)(i => arr(1 + 2 * i + 1).toDouble)
9-
10-
val eps = 1e-9
11-
var count = 0
12-
13-
for (i <- 0 until n; j <- (i + 1) until n; k <- (j + 1) until n) {
14-
val (ax, ay) = (px(i), py(i))
15-
val (bx, by) = (px(j), py(j))
16-
val (cx, cy) = (px(k), py(k))
17-
18-
val d = 2.0 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by))
19-
if (math.abs(d) >= eps) {
20-
val ux = ((ax*ax + ay*ay) * (by - cy) +
21-
(bx*bx + by*by) * (cy - ay) +
22-
(cx*cx + cy*cy) * (ay - by)) / d
23-
val uy = ((ax*ax + ay*ay) * (cx - bx) +
24-
(bx*bx + by*by) * (ax - cx) +
25-
(cx*cx + cy*cy) * (bx - ax)) / d
26-
27-
val rSq = (ux - ax) * (ux - ax) + (uy - ay) * (uy - ay)
28-
29-
val valid = (0 until n).forall { m =>
30-
m == i || m == j || m == k || {
31-
val distSq = (ux - px(m)) * (ux - px(m)) + (uy - py(m)) * (uy - py(m))
32-
distSq >= rSq - eps
33-
}
34-
}
35-
36-
if (valid) count += 1
7+
val points = Array.tabulate(n) { i =>
8+
(arr(1 + 2 * i), arr(1 + 2 * i + 1))
9+
}
10+
11+
def cross(o: (Int, Int), a: (Int, Int), b: (Int, Int)): Long =
12+
(a._1 - o._1).toLong * (b._2 - o._2) - (a._2 - o._2).toLong * (b._1 - o._1)
13+
14+
val base = points(0)
15+
val allCollinear = points.drop(2).forall(point => cross(base, points(1), point) == 0L)
16+
if (allCollinear) return 0
17+
18+
val sorted = points.sortBy(point => (point._1, point._2))
19+
20+
val lower = scala.collection.mutable.ArrayBuffer[(Int, Int)]()
21+
for (point <- sorted) {
22+
while (lower.length >= 2 && cross(lower(lower.length - 2), lower(lower.length - 1), point) <= 0L) {
23+
lower.remove(lower.length - 1)
24+
}
25+
lower += point
26+
}
27+
28+
val upper = scala.collection.mutable.ArrayBuffer[(Int, Int)]()
29+
for (point <- sorted.reverse) {
30+
while (upper.length >= 2 && cross(upper(upper.length - 2), upper(upper.length - 1), point) <= 0L) {
31+
upper.remove(upper.length - 1)
3732
}
33+
upper += point
3834
}
3935

40-
count
36+
val hullVertices = lower.length + upper.length - 2
37+
2 * n - 2 - hullVertices
4138
}
4239
}

algorithms/graph/2-sat/scala/TwoSat.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ object TwoSat {
5555
if (low(u) == dfn(u)) {
5656
sccCnt += 1
5757
var v = -1
58-
do {
58+
var draining = true
59+
while (draining) {
5960
v = stack.pop()
6061
inStack(v) = false
6162
sccId(v) = sccCnt
62-
} while (u != v)
63+
draining = u != v
64+
}
6365
}
6466
}
6567

algorithms/graph/dijkstras/scala/Dijkstra.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package algorithms.graph.dijkstras
22

3-
import scala.collection.mutable
4-
import scala.math.Ordering
3+
import _root_.scala.collection.mutable
4+
import _root_.scala.math.Ordering
55

66
object Dijkstra {
77
private val INF = 1000000000

algorithms/graph/dinic/scala/Dinic.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package algorithms.graph.dinic
22

3-
import java.util.LinkedList
4-
import java.util.Queue
5-
import scala.collection.mutable.ArrayBuffer
6-
import scala.math.min
3+
import _root_.scala.collection.mutable.ArrayBuffer
4+
import _root_.scala.math.min
75

86
object Dinic {
97
case class Edge(to: Int, rev: Int, cap: Long, var flow: Long)
@@ -34,9 +32,9 @@ object Dinic {
3432
val ptr = new Array[Int](n)
3533

3634
def bfs(): Boolean = {
37-
java.util.Arrays.fill(level, -1)
35+
_root_.java.util.Arrays.fill(level, -1)
3836
level(s) = 0
39-
val q: Queue[Int] = new LinkedList()
37+
val q: _root_.java.util.Queue[Int] = new _root_.java.util.LinkedList[Int]()
4038
q.add(s)
4139

4240
while (!q.isEmpty) {
@@ -81,12 +79,14 @@ object Dinic {
8179

8280
var flow: Long = 0
8381
while (bfs()) {
84-
java.util.Arrays.fill(ptr, 0)
82+
_root_.java.util.Arrays.fill(ptr, 0)
8583
var pushed: Long = 0
86-
do {
84+
var keepPushing = true
85+
while (keepPushing) {
8786
pushed = dfs(s, Long.MaxValue)
8887
flow += pushed
89-
} while (pushed != 0)
88+
keepPushing = pushed != 0
89+
}
9090
}
9191

9292
flow.toInt

algorithms/graph/prims-fibonacci-heap/scala/PrimsFibonacciHeap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object PrimsFibonacciHeap {
1212
val inMst = Array.fill(n)(false)
1313
val key = Array.fill(n)(INF)
1414
key(0) = 0
15-
val pq = scala.collection.mutable.PriorityQueue[(Int, Int)]()(Ordering.by[(Int, Int), Int](_._1).reverse)
15+
val pq = scala.collection.mutable.PriorityQueue.empty[(Int, Int)](using Ordering.by[(Int, Int), Int](_._1).reverse)
1616
pq.enqueue((0, 0))
1717
var total = 0
1818

algorithms/graph/prims/scala/Prim.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Prim {
1111
key(0) = 0
1212

1313
// Priority queue: (weight, vertex)
14-
val pq = mutable.PriorityQueue[(Int, Int)]()(Ordering.by[(Int, Int), Int](-_._1))
14+
val pq = mutable.PriorityQueue.empty[(Int, Int)](using Ordering.by[(Int, Int), Int](-_._1))
1515
pq.enqueue((0, 0))
1616

1717
var totalWeight = 0

0 commit comments

Comments
 (0)