编程介的小学生 2017-08-27 10:14 采纳率: 20.5%
浏览 613
已采纳

Split the Rectangle

Alice comes up with a new game and wants to play with Bob.

There is one rectangle on the paper initially, we define its lower-left corner's coordinate is (xL, yL) and upper-right corner's coordinate is (xR, yR).

Bob has executed the step as description below N times:

Bob should select one empty rectangle. If the rectangle is the initial one or is split by one vertical segment, he should split it into two parts by drawing one horizontal segment; otherwise he should split the rectangle into two parts by drawing one vertical segment. An empty rectangle means there is no segment in this rectangle except its only four boundary segments.

You should pay attention that there are only two kinds segments: vertical segment and horizontal segment.

Now Bob has several queries. In each query, Bob selects two target points in the paper. (You can assume that all given target points are always located inside the initial rectangle and not in any drawing segments.) He wants Alice to answer the question as soon as possible: Alice can erase several existing segments, and make two target points in one empty rectangle, and she should answer how many empty rectangles at most would be left at last.

But there are some restrictions: Alice cannot erase segments of the initial rectangle (the (xL, yL) to (xR, yR) one), she can only erase segments drew by Bob; if Alice want to erase one segment, both sides of the segment must be empty rectangles, and after erase it, the two empty rectangles must combine to one bigger empty rectangle; if erasing an existing segment will lead to a disconnected graph, the operation is forbidden.

Input

There are multiple test cases.

The first line contains four integers xL, yL, xR, yR indicating the coordinates of the lower-left corner and the upper-right corner of the initial huge rectangle respectively. (-100,000 ≤ xL, yL, xR, yR ≤ 100,000, xL< xR, yL< yR)

The next line contains two integers N and Q. (1 ≤ N, Q ≤ 1000)

The next N lines each line contains four integers x1, y1, x2, y2 indicating the coordinates of two endpoints of one drawing segments. (-100,000 ≤ x1, y1, x2, y2 ≤ 100,000, x1=x2|y1=y2)

The next Q lines each line contains four integers xA, yA, xB, yB indicating the coordinates of two target points in this query. (-100,000 ≤ xA, yA, xB, yB ≤ 100,000).

Output

For each test case, output Q lines, output the answer of each query in each line.

Sample Input

-10 -10 10 10
5 1
-10 0 10 0
5 -10 5 0
-5 0 -5 10
-5 5 10 5
5 -5 10 -5
0 -3 7 -3
0 0 4 4
3 2
0 2 4 2
2 0 2 2
2 2 2 4
1 1 1 3
1 1 3 1
-10 -10 10 10
3 4
-10 0 10 0
0 -10 0 0
0 0 0 10
-9 -9 -8 -8
-9 -9 -9 9
-9 -9 9 -9
-9 -9 9 9
Sample Output

4
1
3
4
1
3
1

  • 写回答

1条回答

  • threenewbee 2017-09-10 15:53
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题