QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#8371. Mirrors

统计

There are two mirrors inside a box of size $[-L, L] \times [-L, L]$.

Each mirror is a line segment, and both sides of the mirror can reflect light. The two mirrors share a common endpoint.

A laser beam is emitted from point $(x, y)$ in the direction of $(x+a, y+b)$. This means that if there were no mirrors or box boundaries, the laser would pass through $(x+a, y+b)$. How many times does the laser reflect off the mirrors in total?

If a light ray parallel to a mirror hits an endpoint of that mirror, it is considered not to reflect. If it is not parallel, hitting an endpoint is considered a reflection.

Input

The first line contains two integers $T$ and $L$, representing the number of test cases and the size of the box.

Following this are $T$ lines, each containing 10 integers:

  • The first 6 integers are $x_1, y_1, x_2, y_2, x_3, y_3$, representing two mirrors: the segment from $(x_1, y_1)$ to $(x_2, y_2)$ and the segment from $(x_2, y_2)$ to $(x_3, y_3)$.
  • The last 4 integers are $x, y, a, b$, representing that the laser is emitted from $(x, y)$ in the direction of $(x+a, y+b)$, meaning that if there were no mirrors or box, the laser would pass through $(x+a, y+b)$.

Output

Output $T$ lines, each containing the total number of reflections for that test case.

Constraints

$1 \le T \le 50\,000$, $1 \le L \le 1000$.

Examples

Input 1

2 10
9 -6 -8 -10 -6 -2 -3 3 -5 1
8 -10 -2 8 -9 1 -2 -3 10 4

Output 1

0
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.