Cow and Friend

Cow and Friend_第1张图片
Cow and Friend_第2张图片

题意:牛牛有N个喜欢的数,他想从坐标原点跳到(x,0)点,他每次跳跃的距离只能的他喜欢的数请问从原点到X最少跳几次。

思路:每次都跳最大的步数如果不能直接跳完,最后2步走折线。

#include
#include
#include
#define MAXX 100005
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = 2e5 + 5;
const int mod = 1e9 + 7;
//const double PI = 3.141592653589793238462643383279;
const double PI = 3.1415926535;
const double esp = 1e-10;

ll pow_mod(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res = res * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}

int a[1000005];
map<int, int> mp;
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, d;
        mp.clear();
        cin >> n >> d;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
            mp[a[i]] = 1;
        }
        sort(a + 1, a + n + 1);
        if (mp[d]) {
            cout << 1 << endl;
        }
        else
        {
            cout << max(2, (d + a[n] -1)/ a[n]) << endl;
        }
          
       


    }

    return 0;
}

你可能感兴趣的:(CF)