数据范围
1≤T≤1000,
1≤n≤105,
1≤x≤109,
1≤ai≤109,ai 各不相同。
保证同一测试点内所有 n 的和不超过 105。
输入样例:
4
2 4
1 3
3 12
3 4 5
1 5
5
2 10
15 4
输出样例:
2
3
1
2
首先要注意的一个点是,兔子可以跳到非整数点上,而且不是一定要在x轴上跳。
所以我们可以通过两次长的跳跃来达到在x轴上的短距离跳跃效果
maxx是最大的跳跃距离
当maxx>=x,我们找出有没有与x相等的跳跃距离,有的话跳一下就好,没有的话就用两次长距离跳跃来代替
当max<x,我们只采用最长距离跳跃,经过多次跳跃肯定会跳到(x,x+max),然后只需要用倒数两次跳跃来达到x点即可(斜上跳,在斜下跳)
AC代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+3;
int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
ll x;
scanf("%d %lld",&n,&x);
bool flag=0;
ll maxx=0;
for(int i=1;i<=n;++i){
ll inp;
scanf("%lld",&inp);
if(x==inp)flag=1;
maxx=max(maxx,inp);
}
ll ans=0;
if(x<=maxx){
if(flag)ans=1;
else ans=2;
}
else ans=(x+maxx-1)/maxx;
printf("%lld\n",ans);
}
return 0;
}