#P4468. [SCOI2007] 折纸
[SCOI2007] 折纸
Description
There is a square sheet of paper on the table with edges parallel to the coordinate axes. The lower-left corner is at , and the upper-right corner is at . Next, you will execute folding commands. Each command is specified by two distinct points and . When executing a command, fold the current work along the line through , and fold the right side of the directed segment toward the left side (the left side remains unchanged).
After all folds, you need to punch a hole in the work and thread a string through it to hang it on the wall. The hole’s position is crucial: if it goes through too many layers of paper, punching the hole is difficult; if it goes through too few layers, the work may tear when hung. To choose a suitable hole position, you need to compute, for each candidate position, the number of layers the hole passes through. If the hole lies exactly on the boundary of a layer (within ), that layer is not counted.
This problem uses a simplified model: the paper has zero thickness, so each folding operation can be performed perfectly.
Input Format
The first line contains an integer , the number of folds. Each of the next lines contains four real numbers , representing the directed segment used for that fold.
The next line contains a positive integer , the number of candidate positions. Each of the following lines contains two real numbers , representing a candidate position.
Output Format
For each candidate position, output one line containing an integer, which is the number of layers the hole passes through at that position.
2
-0.5 -0.5 1 1
1 75 0 75
6
10 60
80 60
30 40
10 10
50 50
20 50
4
2
2
0
0
2
Hint

Constraints:
- of the testdata satisfy .
- of the testdata satisfy , .
Translated by ChatGPT 5
京公网安备 11011102002149号