QOJ.ac

QOJ

Time Limit: 10 s Memory Limit: 512 MB Total points: 100

#4614. 我的生命已如风中残烛

統計

九条可怜是一个贪玩的女孩子。

这天她在一堵墙钉了 $n$ 个钉子,第 $i$ 个钉子的坐标是 $(x_i,y_i)$。接着她又在墙上钉上了 $m$ 根绳子,绳子的一端是点 $s_i(sx_i,sy_i)$,绳子经过点 $t_i(tx_i,ty_i)$,同时绳子的长度是 $L_i$。其中 $s_i$ 点是在墙上的,而另一个端点是可以移动的。初始情况下绳子是紧绷的一条直线段。

接着,对每一根绳子可怜都进行了一次游戏。在第 $i$ 次游戏中,可怜会捏着第 $i$ 根绳子的活动端点进行顺时针移动,移动过程中每时每刻绳子都是紧绷的。

不难发现绳子每时每刻都在以某一个位置为圆心作顺时针的圆周运动。初始情况下圆心是绳子的固定端点 $s$,但是在运动的过程中圆心可能会不断发生变化,如下图所示:

problem_4614_1.png

图中左侧红点为钉子所在的点,右侧红点为绳子的固定端点,其他颜色的点为虚拟点,活动端点为紫点;绳子从紫点开始运动,在运行到蓝点时绳子绕上左侧红点的钉子,因此活动端点更换了圆心和半径,继续作顺时针的圆周运动。接着活动端点会运行到绿点,并且接下来活动端点会一直绕左侧钉子不停地做圆周运动。

不难发现绳子的运动是不会停止的,因此可怜在她感觉累了之后就会停下来。但是作为一个好奇心满满的女孩子,可怜决定对每一根绳子计算一下如果绳子无限的运行下去,那么它的圆心会切换多少次(包括初始的圆心)。不难发现这个数值一定是有限的。

这里对游戏过程进行一定程度的假设来简化问题:

  1. 活动端点在运动的过程中距离每一个钉子的欧几里得距离始终大于等于 $9 \times 10^{-4}$。
  2. 钉子的坐标两两不同但可能有多点共线
  3. 钉子的体积以及绳子的体积可以忽略不计。在游戏的过程中每一段绳子之间不会互相影响。
  4. 初始情况下绳子距离每一个钉子的最近欧几里得距离大于等于 $9 \times 10^{-4}$。
  5. 每一根绳子初始粘着的端点不会影响绳子的运动,即绳子不会绕回到端点上

输入格式

从标准输入读入数据。

第一行输入一个整数 $T$,表示数据组数。

每组数据第一行为两个整数 $n,m$,表示钉子数和绳子数。

接下来 $n$ 行,每行两个整数 $x_i,y_i$ 表示钉子的坐标。

接下来 $m$ 行,每行五个整数 $sx_i,sy_i,tx_i,ty_i,L_i$ 表示一段绳子,含义如上所述。

输出格式

输出到标准输出。

对于每组数据的每组询问,输出一行一个整数表示运行的过程中圆心变化了多少次。

不同数据组数之间无需空行隔开。

样例一

input

2
5 3
0 0
2 0
2 2
0 2
1 1
1 3 10 3 10
1 3 10 3 20
1 3 10 3 30
3 1
0 0
100 0
1000 0
1 3 10 3 1000000000

output

6
11
16
1000001

样例二

见下发文件。

为了选手的身体健康,可怜决定临时加上一个大样例。但是因为是 IOI 赛制,可怜不想让大样例太强。

大样例如下图所示:

problem_4614_2.png

其中两种颜色的”点“分别表示钉子和询问。为什么询问看起来像是一个点呢,因为每一个询问都是长度为 $1$ 的线段,而坐标范围又很大,所以看起来就是一个点啦。

不难发现每一个询问的答案都是 $1$。

限制与约定

对于前 $10\%$ 的数据,$n \leq 2$。

对于前 $20\%$ 的数据,$n \leq 3$。

对于前 $30\%$ 的数据,$n \leq 10$。

对于前 $60\%$ 的数据,$n \leq 100$,$m \leq 100$。

对于 $100\%$ 的数据,$1 \leq n \leq 500$,$1 \leq m \leq 500$,$1\leq T \leq 10$。

对于 $100\%$ 的数据,$0 \leq |x_i|,|y_i|,|sx_i|,|sy_i|,|tx_i|,|ty_i| \leq 10^4$,$1 \leq L_i \leq 10^9$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.