Here is what I have so far
problem link: https://dmoj.ca/problem/ccc14s4
I took inputs, sorted them into events
for (Glass glass : glasses) {
events.add(new Event(glass.x1, glass.y1, glass.y2, glass.tintLevel));
events.add(new Event(glass.x2, glass.y1, glass.y2, -glass.tintLevel));
}
and converted them into arrays
TreeSet<Integer> yIntervals = new TreeSet<>();
for (Glass glass : glasses) {
yIntervals.add(glass.y1);
yIntervals.add(glass.y2);
}
Integer[] yValues = yIntervals.toArray(new Integer[0]);
here is my loop for every pair
for (Event event : events) {
int x = event.x;
int y1 = event.y1;
int y2 = event.y2;
int value = event.value;
totalArea += (x - prevX) * getArea(yValues, t, y1, y2, value);
prevX = x;
}
I'm struggling to come up with a working getArea method for this question.
You are laying N rectangular pieces of grey-tinted glass to make a stained glass window. Each piece of glass adds an integer value "tint-factor". Where two pieces of glass overlap, the tint-factor is the sum of their tint-factors.