ETSR '23 Onsite Round 1 Problem 2 - Origami

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

There is a square piece of paper. The vertices of the paper are (0,0), (0,100), (100,0), (100,100) in 2D Cartesian coordinates. In other words, it is a square paper with side length 100. There are n \; (0 \leq n \leq 8) folding operations.

Each folding operation can be described using two points P_1 = (x_1,y_1) and P_2 = (x_2,y_2). You will fold the current piece of work along the line determined by P_1 and P_2, and the portion to the right of the vector \vec{P_1P_2} should be folded to the left. Note that the whole line through the points, not just the segment, is folded. See the explanation for the sample input if you are not yet familiar with the notions of left and right.

Now you are given q \; (1 \leq q \leq 50) points. You need to compute, for each point (x,y), the number of layers of paper at that point in the end.

For additional guarantees satisfied by the input, see the Constraints section.

Input Specification

The first line consists of an integer n \; (0 \leq n \leq 8) denoting the number of folds.

In the following n lines, each line has four floating point numbers with at most 4 digits after the decimal point x_1,y_1,x_2,y_2 describing each fold.

Next, there is a positive integer q \; (1 \leq q \leq 50) denoting the number of query points.

In the following q lines, each line consists of two floating point numbers with at most 4 digits after the decimal point x,y denoting a query point.

Output Specification

For each query, output a line with an integer denoting the number of layers of paper at point (x,y).

Sample Input

2
100 0.0 0 100
50 50 0 50
5
75 75.0
10 80
20.0000 40
20 10
70 10

Sample Output

0
0
4
2
2

Explanation

You start with a piece of paper with vertices (0,0), (0,100),(100,0),(100,100).

In the first fold, you will fold along the main diagonal of the paper. Now the paper is folded into two layers: the paper is now a triangle with vertices (0,0), (0,100), (100,0). The lightly shaded orange area represents the area that is folded to the left

In the second fold, you will fold along the line y = 50: you will fold the portion above it down. After that, the shape of the paper will be a trapezoid with vertices (0,50), (50,50), (100,0), (0,0). Furthermore, over the triangle bounded by (0,50),(50,50),(0,0), there are 4 layers, while in the rest of the paper there are 2 layers. In the below diagram, the lightly shaded orange area represents the region that is folded left/down, the dark shaded blue regions represent the part where there are 4 layers, and lightly shaded blue regions represent the part where there are 2 layers.

Constraints

For all test cases, 0 \leq n \leq 8, 1 \leq q \leq 50. For all fold lines \vec{P_1P_2} where P_1 = (x_1,y_1) and P_2 = (x_2,y_2), we have -200 \leq x_1,y_1,x_2,y_2 \leq 200. For all query points (x_i,y_i), we have -200 \leq x_i, y_i \leq 200. All floating point numbers in the input have at most 4 digits after the decimal point.

Furthermore, the test data generated satisfy the following constraints:

  • The minimum area of any layer is at least 10^{-3}.
  • When viewed as a simple polygon (no vertices in the middle of boundaries), each layer has side lengths at least 10^{-3}.
  • The distance between a query point and the boundary of a layer is at least 10^{-3}.

It is possible that the boundary of a layer is contained in the line to be folded.

Scoring

  • Subtask 1 (5 points): n = 0.
  • Subtask 2 (21 points): n = 1.
  • Subtask 3 (14 points): n = 2.
  • Subtask 4 (30 points): all folds are parallel to the x-axis or the y-axis.
  • Subtask 5 (30 points): no additional constraints. Depends on all previous subtasks.

Comments

There are no comments at the moment.