Line intersection - MarisaOJ: Marisa Online Judge

Line intersection

Time limit: 1000 ms
Memory limit: 256 MB
Given q questions. Each question give you four points A(xA,yA),B(xB,yB),C(xC,yC),D(xD,yD). Find the point of intersection of lines AB and CD. It is guaranteed that there is only one intersection point. ### Input - The first line contains an integer q. - The next q lines, each line contains eight integers xA,yA,xB,yB,xC,yC,xD,yD. ### Output - Print q lines. Each line, print the point of intersection for the corresponding question. Your answer will be considered correct if its absolute or relative error does not exceed 10−3. In other words, your answer, x, will be compared to the correct answer, y. If |x−y|<10−3, then your answer will be considered correct. ### Constraints - 1≤q≤105. - −106≤x,y≤106. ### Example Input: 100111001 Output: 0.50.5