• 51Nod 1105 第K大的数 二分答案


    很典型的二分答案的题目 码着

    #include<iostream>  
    #include<algorithm>
    #include<string>
    #include<string.h>
    typedef long long ll;
    using namespace std;
    const int MAX = 5e4 + 5;
    ll n, k, a[MAX], b[MAX];
    bool C(ll mid)
    {
        ll j = n, cnt = 0;
        for (ll i = 1; i <= n; i++)
        {
            while (j > 0)
            {
                if (a[i] * b[j] > mid)
                    j--;
                else break;
            }
            cnt += j;
        }
        return cnt >= k;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin >> n >> k;
        k = n*n - k+1;
        for (int i = 1; i <= n; i++)
            cin >> a[i]>> b[i];
        sort(a+1, a + n+1);
        sort(b+1, b + n+1);
        ll l = a[1] * b[1], r = a[n] * b[n];
        for(int i=0;i<100;i++)
        {
            ll mid = (l + r) >> 1;
            if (C(mid)) r = mid;
            else l = mid;
        }
        cout << r << endl;
        return 0;
    }
  • 相关阅读:
    LeetCode 55
    LeetCode 337
    LeetCode 287
    LeetCode 274
    LeetCode 278
    LeetCode 264
    LeetCode 189
    LeetCode 206
    LeetCode 142
    LeetCode 88
  • 原文地址:https://www.cnblogs.com/Egoist-/p/7663701.html
Copyright © 2020-2023  润新知