#3036. Origami
Origami
Description
Origami is the old Japanese art of folding single sheets of paper into the forms of animals, flowers and other figures. Recently a programmable machine was constructed to make some of the simpler kinds of origami. This machine has a large board with coordinate system drawn on it. First, a square sheet of paper is placed on the board so that the lower left corner has coordinates (0; 0) and the upper right corner has coordinates (100; 100). Then the machine follows the program. The program consists of several steps. Each step is given as a line in the coordinate system at which the origami is to be folded. The line is represented by two points: the paper is folded from right to left when one is facing the second point from the first. The paper on the left side of the line remains in place and the paper on the right side is folded flat on top of it. After the execution of the last step one gets a resulting origami. It is necessary to pierce the origami in order make a hole for hanging. It is important to choose the place for making a hole carefully, because if the origami is too thick in this place it is difficult to make a hole, and if it is too thin it is not strong enough for hanging. Your task is to write a program that computes the number of layers of a paper in the given point.
Input The first part of the input file contains a program for the origami machine. The first line contains the number of steps of the program. One line follows for each step of the program. Each line contains fold-line coordinates x1 , y1 , x2 , y2 (real numbers) separated by spaces. The program consists of at most 8 steps. The second part of the input file contains several potential points for making a hole. The first line contains the number of such places and each of the next lines contains coordinates of the point.
Output
For each of the potential points write a line containing the number of layers pierced through in this point. Note: Assume that the paper has zero thickness and therefore folds ideally. The pierced hole is a single point. The layers pierced exactly at the border of the paper or at the folded edge (within 0.000001) do not count as pierced layers.
输入数据 1
2
-0.5 -0.5 1 1
1 75 0 75
6
10 60
80 60
30 40
10 10
50 50
20 50
输出数据 1
4
2
2
0
0
2
Source
Waterloo local 1999.10.02
描述
折纸是一种古老的日本艺术,它将单张纸折叠成动物、花朵以及其他形状。最近,人们制造出了一台可编程的机器,用来制作一些较为简单的折纸作品。这台机器有一块大的板子,上面画有坐标系。首先,将一张正方形的纸放置在板子上,使得纸的左下角坐标为,右上角坐标为。然后,机器按照程序运行。该程序由若干步骤组成。每一步都由坐标系中的一条直线来表示,沿着这条直线对折纸张。这条直线由两个点来表示:当从第一个点朝向第二个点看时,纸张从右向左折叠。直线左边的纸张保持不动,右边的纸张则平展地折叠在左边纸张的上面。在执行完最后一步后,就得到了最终的折纸作品。为了给折纸作品打一个用于悬挂的孔,需要在上面穿孔。仔细选择穿孔的位置非常重要,因为如果在这个位置折纸的层数太厚,就很难穿孔;而如果层数太薄,又不足以承受悬挂的重量。你的任务是编写一个程序,计算给定的点处纸张的层数。
输入 输入文件的第一部分包含折纸机器的程序。第一行包含程序的步骤数。接下来每行对应程序的一个步骤。每行包含折痕线的坐标、、、(实数),这些坐标之间用空格分隔。该程序最多包含8个步骤。输入文件的第二部分包含几个可能的穿孔位置。第一行包含这样的位置的数量,接下来的每一行包含一个点的坐标。
输出
对于每一个可能的穿孔位置,输出一行,包含在该点处穿过的纸张层数。注意:假设纸张的厚度为零,因此可以理想地折叠。所穿的孔是一个单点。恰好穿在纸张边缘或折叠边缘(在范围内)的层不计算为穿过的层数。
输入数据 1
2
-0.5 -0.5 1 1
1 75 0 75
6
10 60
80 60
30 40
10 10
50 50
20 50
输出数据 1
4
2
2
0
0
2
来源
滑铁卢地区赛 1999年10月2日