CF1307B.Cow and Friend
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play!
More specifically, he wants to get from (0,0) to (x,0) by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance between the endpoints of a hop is one of its n favorite numbers: a1,a2,…,an. What is the minimum number of hops Rabbit needs to get from (0,0) to (x,0)? Rabbit may land on points with non-integer coordinates. It can be proved that Rabbit can always reach his destination.
Recall that the Euclidean distance between points (xi,yi) and (xj,yj) is (xi−xj)2+(yi−yj)2.
For example, if Rabbit has favorite numbers 1 and 3 he could hop from (0,0) to (4,0) in two hops as shown below. Note that there also exists other valid ways to hop to (4,0) in 2 hops (e.g. (0,0) → (2,−5) → (4,0)).
Here is a graphic for the first example. Both hops have distance 3, one of Rabbit's favorite numbers.
In other words, each time Rabbit chooses some number ai and hops with distance equal to ai in any direction he wants. The same number can be used multiple times.
贝茜的朋友实在太多了,因为她可是大家最喜爱的奶牛!她的新朋友兔子正试图跳过来和她一起玩耍!
更具体地说,兔子希望从点 (0,0) 出发,经过若干次跳跃,最终到达点 (x,0)。他只愿意在二维平面上从一个点跳到另一个点,当且仅当该次跳跃起点与终点之间的欧几里得距离等于他 n 个最喜爱的数之一:a1,a2,…,an。问:兔子从 (0,0) 到达 (x,0) 所需的最少跳跃次数是多少?兔子可以落在坐标非整数的点上。可以证明:兔子总能到达目的地。
回忆一下,两点 (xi,yi) 与 (xj,yj) 之间的欧几里得距离为 (xi−xj)2+(yi−yj)2。
例如,若兔子喜爱的数字为 1 和 3,则他可以从 (0,0) 经过两次跳跃到达 (4,0),如下图所示。注意,也存在其他合法方式,用 2 次跳跃到达 (4,0)(例如:(0,0)→(2,−5)→(4,0))。
这是第一个例子的示意图。两次跳跃的距离均为 3,而 3 是兔子喜爱的数字之一。
换言之,每次跳跃时,兔子选择某个喜爱的数 ai,并以 ai 为距离、朝任意方向跳跃一次。同一个数可被重复使用多次。
输入格式
The input consists of multiple test cases. The first line contains an integer t (1≤t≤1000) — the number of test cases. Next 2t lines contain test cases — two lines per test case.
The first line of each test case contains two integers n and x (1≤n≤105, 1≤x≤109) — the number of favorite numbers and the distance Rabbit wants to travel, respectively.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — Rabbit's favorite numbers. It is guaranteed that the favorite numbers are distinct.
It is guaranteed that the sum of n over all the test cases will not exceed 105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。接下来的 2t 行包含测试用例,每个测试用例占两行。
每个测试用例的第一行包含两个整数 n 和 x(1≤n≤105,1≤x≤109),分别表示兔子喜欢的数字个数以及兔子希望行走的距离。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),表示兔子喜欢的数字。保证这些喜欢的数字互不相同。
保证所有测试用例中 n 的总和不超过 105。
输出格式
For each test case, print a single integer — the minimum number of hops needed.
对于每个测试用例,输出一个整数——所需的最少跳跃次数。
输入输出样例
输入#1
4 2 4 1 3 3 12 3 4 5 1 5 5 2 10 15 4
输出#1
2 3 1 2
说明/提示
The first test case of the sample is shown in the picture above. Rabbit can hop to (2,5), then to (4,0) for a total of two hops. Each hop has a distance of 3, which is one of his favorite numbers.
In the second test case of the sample, one way for Rabbit to hop 3 times is: (0,0) → (4,0) → (8,0) → (12,0).
In the third test case of the sample, Rabbit can hop from (0,0) to (5,0).
In the fourth test case of the sample, Rabbit can hop: (0,0) → (5,102) → (10,0).
样例的第一个测试用例如上图所示。兔子可以先跳到点 (2,5),再跳到点 (4,0),共需两次跳跃。每次跳跃的距离均为 3,而 3 是它最喜欢的一个数字。
样例的第二个测试用例中,兔子的一种三跳方案为:(0,0) → (4,0) → (8,0) → (12,0)。
样例的第三个测试用例中,兔子可以从 (0,0) 直接跳到 (5,0)。
样例的第四个测试用例中,兔子可以按如下方式跳跃:(0,0) → (5,102) → (10,0)。
输入解题思路,AI测评打分。不知道怎么写?