Holiday cattle passenger pick-team tournament 1 I.

link:

https://ac.nowcoder.com/acm/contest/918/I

Meaning of the questions:

A spectacular cattle grazing in the General Assembly will hold a Farmer John's farm!
Cows from around the world will reach the local airport, participants to come and graze. Specifically, there are N cows arrival airport (1≤N≤10 ^ 5), where i cows arrival time ti (0≤ti≤10 ^ 9). Farmer John arranged M (1≤M≤10 ^ 5) buses to the airport to meet these cows. Per bus can take the C cows (1≤C≤N). Farmer John is at the airport waiting for the arrival of the cows, and the cows were prepared to arrange arrived by bus. When the last one in a cow ride buses arriving, you can start the car bus. Farmer John wants to do a good sponsor, so cows do not want to wait too long at the airport. If Farmer John reasonable coordination of these buses, the minimum waiting the longest cows waiting time is how much? The difference between the departure time of a cow waiting time equal to the time of her arrival and she rides the bus.

Input guarantee MC≥N.

Ideas:

Dichotomous answer

Code:

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
 
int Times[MAXN];
 
bool Check(int x)
{
    int he = 1, now = 1;
    for (int c = 1;c <= m;c++)
    {
        while (now <= n && now-he+1 <= k && Times[now]-Times[he] <= x)
            now++;
        he = now;
    }
    if (he > n)
        return true;
    return false;
}
 
int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1;i <= n;i++)
        scanf("%d", &Times[i]);
    sort(Times+1, Times+1+n);
    int l = 0, r = Times[n];
    int res = 1e9;
    while (l<r)
    {
//        cout << l << ' ' << r << endl;
        int mid = (l+r)/2;
        if (Check(mid))
        {
            res = min(res, mid);
            r = mid;
        }
        else
            l = mid+1;
    }
    cout << res << endl;
 
    return 0;
}

Guess you like

Origin www.cnblogs.com/YDDDD/p/10995673.html