zoukankan      html  css  js  c++  java
  • UVA 11389 The Bus Driver Problem

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82842#problem/D

    In a city there are n bus drivers. Also there are n morning bus routes & n afternoon bus routes with various lengths. Each driver is assigned one morning route & 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 & 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

    Output for Sample Input

    2 20 5

    10 15

    10 15

    2 20 5

    10 10

    10 10

    0 0 0

    50

    0

    解题思路:这个题目的意思是怎样分配使公交车司机加班费减至最少,n个司机,早上走n条路径,每个路经是x长度,晚上走n条路径,每个路径是X长度,d表示一个司机一天固定要跑的长度,r表示价格,每超过y个长度,则司机可获得y*r的加班费。

    要使加班费减到最低,则需要对上午所跑长度和下午所跑长度分别进行排序,一个从小到大,一个从大到小,这样二者之和均能降到最小,因此加班费也会控制到最小。

    程序代码          :

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdio>
     4 
     5 using namespace std;
     6 const int m=100+5;
     7 int a[m],b[m];
     8 
     9 bool p(int a,int b)
    10 {    return  a>b;}
    11 
    12 inline int max(int a,int b)
    13 {
    14     return a>b?a:b;
    15 }
    16 
    17 int main()
    18 {int n,d,r,i;
    19     while(cin>>n>>d>>r&&(n!=0&&d!=0&&r!=0))
    20     {
    21         for(i=0;i<n;i++)
    22             scanf("%d",&a[i]);
    23 
    24        for(i=0;i<n;i++)
    25             scanf("%d",&b[i]);
    26         sort(a,a+n);
    27        sort(b,b+n,p);
    28        int sum=0;
    29         for(i=0;i<n;i++)
    30             sum+=max(0,(a[i]+b[i]-d));
    31         cout<<sum*r<<endl;
    32     }
    33    return 0;
    34 }
    版权声明:此代码归属博主, 请务侵权!
  • 相关阅读:
    第四次作业--项目选题报告(团队)
    第三次作业--团队展示(团队)
    第二次作业——个人项目实战
    2017软件工程实践
    Unity3D游戏开发——显示物品的仓库UI
    Unity3D游戏开发——物品存储:List与Dictionary
    Unity3D游戏开发——编程实现游戏管理器
    Unity3D游戏开发——访问集中式共享模块的设计模式
    Unity3D游戏开发——收集当前关卡游戏中分散的物件
    福州大学软工1816 K 班助教总结
  • 原文地址:https://www.cnblogs.com/www-cnxcy-com/p/4655464.html
Copyright © 2011-2022 走看看