zoukankan      html  css  js  c++  java
  • General Problem Solving Techniques [Intermediate-1]~G

    In a city there are n bus drivers. Also there are n morning bus routes and n afternoon bus routes with
    various lengths. Each driver is assigned one morning route and one evening route. For any driver, if
    his total route length for a day exceeds d, he has to be paid overtime for every hour after the first d
    hours at a flat r taka / hour. Your task is to assign one morning route and one evening route to each
    bus driver so that the total overtime amount that the authority has to pay is minimized.
    Input
    The first line of each test case has three integers n, d and r, as described above. In the second line,
    there are n space separated integers which are the lengths of the morning routes given in meters.
    Similarly the third line has n space separated integers denoting the evening route lengths. The lengths
    are positive integers less than or equal to 10000. The end of input is denoted by a case with three 0’s.
    Output
    For each test case, print the minimum possible overtime amount that the authority must pay.
    Constraints
    • 1 ≤ n ≤ 100
    • 1 ≤ d ≤ 10000
    • 1 ≤ r ≤ 5
    Sample Input
    2 20 5
    10 15
    10 15
    2 20 5
    10 10
    10 10
    0 0 0
    Sample Output
    50
    0

    解题思路:有n个司机,每个司机都有相同的路程分配量,且每个司机都要上午和下午各开一次车。要求怎样分配才能使司机的加班费用最少,可以考虑贪心,平均分配。使得每个司机都能开一次长路程和短路程(相对情况下)。

    程序代码:

    #include"stdio.h"
    #include"algorithm"
    #include"math.h"
    using namespace std;
    const int N=110;
    int a[N],b[N];
    int cmp(int x,int y)
    {
        return x>y;
    }
    int main()
    {
        int n,d,r,i;
        while(scanf("%d%d%d",&n,&d,&r)&&n&&d&&r)
        {
            fill(a,a+n,0);
            fill(b,b+n,0);
            for(i=0;i<n;i++)
                scanf("%d",&a[i]);
            for(i=0;i<n;i++)
                scanf("%d",&b[i]);
            sort(a,a+n);
            sort(b,b+n,cmp);
            int sum=0;
            for(i=0;i<n;i++)
                sum=sum+max(0,a[i]+b[i]-d);
            printf("%d
    ",sum*r);
        }
        return 0;
    }
  • 相关阅读:
    es5中,一个在js中导入另一个js文件。
    移动端字体小于12号字的时候,line-height居中的问题
    初学者都能懂得 Git 说明
    一探 Vue 数据响应式原理
    文件的命名规则
    Vue 的 watch 和 computed 有什么关系和区别?
    MVC 与 Vue
    博客园皮肤设置
    java使用run和start后的线程引用
    Python改变一行代码实现二叉树前序、中序、后序的迭代遍历
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4865225.html
Copyright © 2011-2022 走看看