zoukankan      html  css  js  c++  java
  • Topcoder Tian Ji‘s Horse Racing

    链接:https://www.nowcoder.com/acm/contest/126/A
    来源:牛客网

    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 32768K,其他语言65536K
    64bit IO Format: %lld
    题目描述
    Tian Ji, one of the military generals of the Qi state during 4th century BC, liked playing horse racing and once he was invited to participate in a horse-racing event hosted by King Wei of Qi. The event lasted for k days and both Tian Ji and King Wei of Qi were all well-prepared for the coming event. Now Tian Ji had n horses with speeds of a1, a2, …, an and King Wei of Qi had n horses with speeds of b1, b2, …, bn. In each day, there were n matches where both of them used one of their own horses. Since the horses would be tired after the match, each horse could be used only once in each day. The excitement of each match was the sum of the speeds of the two horses used in this match. In order to make the event more exciting, the matches in any two different days couldn’t be exactly the same. That is to say, In any two different days, there was at least one horse that had different opponents in the two days. You, the brilliant in the 21st century AD, need to calculate the maximum possible value of the minimum of the excitement in the k×n matches during the k-day event.

    齐国的大将田忌很喜欢赛马,有一回他被齐威王请来赛 k 天马。经过精心的准备,现在田忌有 n 匹速度分别为 a1, a2, …, an 的马,齐威王则有 n 匹速度分别为 b1, b2, …, bn 的马。每天要进行 n 场比赛,每场比赛田忌和齐威王分别会派出一匹马,每匹马每天只能上场一次,每场比赛的精彩程度是上场的两匹马的速度之和。为了让比赛更精彩,任意不同的两天里进行的比赛不能完全相同,也就是说,对于任意不同的两天,存在至少一匹马在这两天比赛的对手不同。你需要计算出这 k 天总计 k×n 场比赛中精彩程度最小值的最大可能值。
    输入描述:
    The first line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ min(n!, 10^9)) — the number of horses they had respectively and the number of days of the event.
    The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 10^9) — the speeds of the n horses Tian Ji had.
    The third line contains n integers b1, b2, …, bn (1 ≤ bi ≤ 10^9) — the speeds of the n horses King Wei of Qi had.

    第一行包含两个整数 n 和 k (1 ≤ n ≤ 50, 1 ≤ k ≤ min(n!, 10^9)),分别表示田忌和齐威王各自拥有的马匹数以及赛马的天数。
    第二行包含 n 个整数 a1, a2, …, an (1 ≤ ai ≤ 10^9),表示田忌拥有的 n 匹马的速度。
    第三行包含 n 个整数 b1, b2, …, bn (1 ≤ bi ≤ 10^9),表示齐威王拥有的 n 匹马的速度。
    输出描述:
    Output one integer, the maximum possible value of the minimum of the excitement in the k×n matches during the k-day event.

    输出一个整数,表示这 k 天总计 k×n 场比赛中精彩程度最小值的最大可能值。
    示例1
    输入
    2 1
    1 2
    1 3
    输出
    3
    示例2
    输入
    2 2
    1 2
    1 3
    输出
    2

    结合代码理解

    /*思路:
    
    求最小值的最大值  二分答案
    满足K天 可以转化为至少有K种匹配方案
    因为是求最小值,所以我们先对两个数组排序
    对于每匹马,我们求出其可以的活动范围num[i],当匹配到第i个数是,其活动区间为(num[i]-i)并且保证活动区间大于零
    
    */
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=110,inf=2e9+7;
    ll a[maxn],b[maxn],n,num[maxn],k;
    double check(int x){
        for (int i=0;i<n;i++) num[i]=0;
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                if(a[i]+b[j]>=x) num[i]++;
            }
        }
        double fg=1;
        for (int i=0;i<n;i++){
            if(num[i]>i) fg*=num[i]-i;
    
            else return 0;
        }
        return fg;
    }
    int main(){
        ios::sync_with_stdio(false);
        cin>>n>>k;
        for (int i=0;i<n;i++) cin>>a[i];
        for (int i=0;i<n;i++) cin>>b[i];
        sort(a,a+n);
        sort(b,b+n);
        int L=0,R=inf;
        while(L<=R){
            ll mid=(0ll+L+R)>>1;
            if(check(mid)>=k) L=mid+1;
            else R=mid-1;
        }
        cout<<R<<endl;
        return 0;
    }
    
  • 相关阅读:
    调度思想-现实中的事物与技术里面其实存在类似道理(转载收藏的一篇好文)
    使用curl发送post或者get数据
    论技术的重要性(转载的一篇文章)
    facebook工具xhprof的安装与使用-分析php执行性能(转载)
    (转载)网站瓶颈发现和解决
    mysql不乱码的思想总结
    如何在同一台机器上安装多个MySQL的实例
    awk的常用操作场景以及工作中涉及到的一些场景实例
    Linux中的yum的配置以及常见报错的处理
    (转载)感触比较深的一篇文章
  • 原文地址:https://www.cnblogs.com/acerkoo/p/9490333.html
Copyright © 2011-2022 走看看