编程介的小学生 2017-09-22 02:23 采纳率: 20.5%
浏览 747
已采纳

Geometry with a ruler

Description

Classic geometric construction is based on two instruments: ruler and compass. However, some constructions are possible using only the ruler. Specifically, let us define that if we have a set of N points, we can select two pairs of them, draw a line through each pair, and construct a new point as an intersection of these two lines. New point can then be added to the set as (N + 1)-th point, and the process repeated.

Such geometric constructions are abstract notions, and attempt to verify them with physical pencil and ruler can lead to errors caused by imprecision of these instruments. So you are tasked to write a program that does exact verification.

Your program must read a set of points and a sequence of constructing operations and find out whether the point with coordinates (0, 0) is one of the constructed points. Note that, similar to physical instruments, floating point calculations performed by computers are also imprecise. This should not, of course, alter verification results.

Input

Input file contains number of points N followed by their integer coordinates x1 y1 x2 y2 ... xN yN. Next comes number of construction operations M followed by M quads of integers ai bi ci di, where k-th quad means that a new point is constructed as an intersection of lines containing pairs of points ai, bi and ci, di. Such a point is guaranteed to exist. Constructed point is assigned a number N + k and can be used in following operations.

Constraints

4 ≤ N ≤ 100, 1 ≤ M ≤ 10, −106 ≤ xi, yi ≤ 106

Output

Output file must contain a single integer — number of the first operation which constructs a point (0, 0), or 0 (zero), if there is no such operation.

Sample Input

Sample Input 1
4
-1 -1 -2 2 2 2 1 -1
1
1 3 2 4
Sample Input 2
4
-1000 -1000 -2000 2000 2001 2000 1000 -1000
1
1 3 2 4
Sample Output

Sample Output 1
1
Sample Output 2
0

  • 写回答

1条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!