Life is a Line |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) |
Total Submission(s): 192 Accepted Submission(s): 71 |
Problem Description There is a saying: Life is like a line, some people are your parallel lines, while others are destined to meet you. Maybe have met, maybe just a matter of time, two unparallel lines will always meet in some places, and now a lot of life (i.e. line) are in the same coordinate system, in a given open interval, how many pairs can meet each other? |
Input There are several test cases in the input. Each test case begin with one integer N (1 ≤ N ≤ 50000), indicating the number of different lines. Then two floating numbers L, R follow (-10000.00 ≤ L < R ≤ 10000.00), indicating the interval (L, R). Then N lines follow, each line contains four floating numbers x1, y1, x2, y2 (-10000.00 ≤ x1, y1, x2, y2 ≤ 10000.00), indicating two different points on the line. You can assume no two lines are the same one. The input terminates by end of file marker. |
Output For each test case, output one integer, indicating pairs of intersected lines in the open interval, i.e. their intersection point’s x-axis is in (l, r). |
Sample Input |
Sample Output |
Author 題目大意: 給出 一個區間 ( l r),給出 n條直線,問這些直線有多少交點在區間内。 思路; 我們先求出給出每條直線在 l r 上交點,如果 兩條直線相交,那麼 a 直線在 l 上的交點 在 b 直線在 l 上的交點下面 并且,a 直線在 r 上的交點在 b 直線與 r 交點的上方,或者是反過來,是以想到用逆序數來解決這個問題。 我們首先按照在 l 上交點 從小到大排序,然後編上序号,按照r上的順序,從大到小排序,統計就可以了。 特殊考慮的地方: 直線和 y 軸平行。 實話,printf 比 cout 快 AC代碼: |