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)(0,0) to (x,0)(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 nn favorite numbers: a_1, a_2, \ldots, a_na1,a2,…,an. What is the minimum number of hops Rabbit needs to get from (0,0)(0,0) to (x,0)(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 (x_i, y_i)(xi,yi) and (x_j, y_j)(xj,yj) is \sqrt{(x_i-x_j)^2+(y_i-y_j)^2}(xi−xj)2+(yi−yj)2.
For example, if Rabbit has favorite numbers 11 and 33 he could hop from (0,0)(0,0) to (4,0)(4,0) in two hops as shown below. Note that there also exists other valid ways to hop to (4,0)(4,0) in 22 hops (e.g. (0,0)(0,0) \rightarrow→ (2,-\sqrt{5})(2,−5) \rightarrow→ (4,0)(4,0)).
Here is a graphic for the first example. Both hops have distance 33, one of Rabbit's favorite numbers.
In other words, each time Rabbit chooses some number a_iai and hops with distance equal to a_iai in any direction he wants. The same number can be used multiple times.
Input
The input consists of multiple test cases. The first line contains an integer tt (1 \le t \le 10001≤t≤1000) — the number of test cases. Next 2t2t lines contain test cases — two lines per test case.
The first line of each test case contains two integers nn and xx (1 \le n \le 10^51≤n≤105, 1 \le x \le 10^91≤x≤109) — the number of favorite numbers and the distance Rabbit wants to travel, respectively.
The second line of each test case contains nn integers a_1, a_2, \ldots, a_na1,a2,…,an (1 \le a_i \le 10^91≤ai≤109) — Rabbit's favorite numbers. It is guaranteed that the favorite numbers are distinct.
It is guaranteed that the sum of nn over all the test cases will not exceed 10^5105.
Output
For each test case, print a single integer — the minimum number of hops needed.
Sample 1
Inputcopy | Outputcopy |
---|---|
4 2 4 1 3 3 12 3 4 5 1 5 5 2 10 15 4 | 2 3 1 2 |
Note
The first test case of the sample is shown in the picture above. Rabbit can hop to (2,\sqrt{5})(2,5), then to (4,0)(4,0) for a total of two hops. Each hop has a distance of 33, which is one of his favorite numbers.
In the second test case of the sample, one way for Rabbit to hop 33 times is: (0,0)(0,0) \rightarrow→ (4,0)(4,0) \rightarrow→ (8,0)(8,0) \rightarrow→ (12,0)(12,0).
In the third test case of the sample, Rabbit can hop from (0,0)(0,0) to (5,0)(5,0).
In the fourth test case of the sample, Rabbit can hop: (0,0)(0,0) \rightarrow→ (5,10\sqrt{2})(5,102) \rightarrow→ (10,0)(10,0).
题意:
在平面直角坐标系中,从(0,0)走到(x,0),有n种步长,问最少几步到达(x,0)。
思路:
如果x大于最长的步长m,那么先每次都选用最长的步长沿x轴走,如若不能整除就在第一次距离x小于2m之后再加两步m走折线;如果x小于最大步长m,判断是否有步长等于x,有就输出1,否则两步m走折线。
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
int a[200000];
void slove(){
int t;
cin>>t;
while(t--){
int n,x;
cin>>n>>x;
int maxn=-1;
for(int i=0;i<n;i++){
cin>>a[i];
maxn=max(maxn,a[i]);
}
if(x>=maxn)
if(x%maxn)cout<<x/maxn+1<<endl;
else cout<<x/maxn<<endl;
else{
int ans=2;
for(int i=0;i<n;i++){
if(x==a[i]){
ans=1;
break;
}
}
cout<<ans<<endl;
}
}
}
int main(){
slove();
}