import java.util.*; import java.util.function.*; import static java.lang.Math.*; public class GardenOfThorns_Godmar { public static void main(String []av) { var sc = new Scanner(System.in); int n = sc.nextInt(); int r = sc.nextInt(); int w = sc.nextInt(); int h = sc.nextInt(); Line bottom = new Line(new P(w, 0), new P(0, 0)); Line top = new Line(new P(w, h), new P(0, h)); Line left = new Line(new P(0, h), new P(0, 0)); Line right = new Line(new P(w, 0), new P(w, h)); double exp = 0; for (int i = 0; i < n; i++) { Circle plant = new Circle(P.read(sc), r); int v = sc.nextInt(); var sector = (BiFunction) (p1, p2) -> p1.sub(plant.c).angleTo(p2.sub(plant.c)) * r * r / 2.0; double area = 0; for (Line side : new Line[] { left, top, right, bottom }) { P [] p = side.intersectsCircle(plant); if (p.length < 2) { area += sector.apply(side.p, side.q); } else { P a = side.q, b = side.p; if (side.isInBounds(p[0])) { area += sector.apply(side.q, p[0]); a = p[0]; } if (side.isInBounds(p[1])) { area += sector.apply(p[1], side.p); b = p[1]; } area += abs(plant.c.signedTriangleArea(a, b)); } } exp += area/(w*h)*v; } System.out.println(exp); } //------------ START of Geometry classes ------------ static class P { final double x, y; P(double x, double y) { this.x = x; this.y = y; } P sub(P that) { return new P(x - that.x, y - that.y); } P add(P that) { return new P(x + that.x, y + that.y); } double dot(P that) { return x * that.x + y * that.y; } P scale(double s) { return new P(x * s, y * s); } // Use hypot() only if intermediate overflow must be avoided; very slow double length() { return sqrt(x*x + y*y); } double length2() { return x * x + y * y; } P normalize() { double n = length(); return n > 0 ? new P(x/n, y/n) : origin(); } P scaleToLength(double l) { return normalize().scale(l); } P project(P a) { return scale(a.dot(this) / length2()); } // angle between two vectors, result is in [0, pi] rad (0-180 deg) double angleTo(P a) { return acos(this.dot(a) / this.length() / a.length()); } public String toString() { return String.format("(%f,%f)", this.x, this.y); } static P read(Scanner s) { return new P(s.nextDouble(), s.nextDouble()); } static P origin() { return new P(0, 0); } double det(P that) { return this.x * that.y - this.y * that.x; } double crossproduct(P that) { return this.det(that); } double dist(P to) { return sub(to).length(); } double signedParallelogramArea(P b, P c) { return (b.sub(this).crossproduct(c.sub(this))); } double signedTriangleArea(P b, P c) { return signedParallelogramArea(b, c) / 2.0; } } static double EPS = 1e-6; static class Line { P p, q, d; Line(P p, P q) { this.p = p; this.q = q; d = q.sub(p); } // project p onto this (infinite) line. Returns point on line P project(P a) { return p.add(d.project(a.sub(p))); } @Override public String toString() { return String.format("[%s => %s]", p, q); } P [] intersectsCircle(Circle c) { P x = project(c.c); double D = x.dist(c.c); // outside by more than EPS if (D > c.R + EPS) return new P[0]; double h = sqrt(max(0, c.R * c.R - D * D)); if (h == 0) return new P[] { x }; return new P[] { x.add(d.scaleToLength(h)), x.add(d.scaleToLength(-h)) }; } /** * Is r contained within the line segment spanned by p/q, * including their endpoints? */ boolean isInBounds(P r) { return abs(p.dist(q) - p.dist(r) - q.dist(r)) <= EPS; } } static class Circle { P c; double R; Circle(P c, double R) { this.c = c; this.R = R; } @Override public String toString() { return String.format("{%s, %.03f}", c, R); } } }