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的加班费。
要使加班费减到最低,则需要对上午所跑长度和下午所跑长度分别进行排序,一个从小到大,一个从大到小,这样二者之和均能降到最小,因此加班费也会控制到最小。
程序代码 :
#include <iostream>
#include <algorithm>
#include <cstdio> using namespace std;
const int m=+;
int a[m],b[m]; bool p(int a,int b)
{ return a>b;} inline int max(int a,int b)
{
return a>b?a:b;
} int main()
{int n,d,r,i;
while(cin>>n>>d>>r&&(n!=&&d!=&&r!=))
{
for(i=;i<n;i++)
scanf("%d",&a[i]); for(i=;i<n;i++)
scanf("%d",&b[i]);
sort(a,a+n);
sort(b,b+n,p);
int sum=;
for(i=;i<n;i++)
sum+=max(,(a[i]+b[i]-d));
cout<<sum*r<<endl;
}
return ;
}
UVA 11389 The Bus Driver Problem的更多相关文章
- UVA 11389 The Bus Driver Problem 贪心水题
题目链接:UVA - 11389 题意描述:有n个司机,n个早班路线和n个晚班路线,给每个司机安排一个早班路线和一个晚班路线,使得每个早班路线和晚班路线只属于一个司机.如果一个司机早班和晚班总的驾驶时 ...
- UVa 11389 - The Bus Driver Problem 难度:0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- 【策略】UVa 11389 - The Bus Driver Problem
题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线.给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r.问如何分配路线才能使加班费最少. 虽然代码看起来 ...
- UVa 11389 (贪心) The Bus Driver Problem
题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...
- The Bus Driver Problem
题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=90648#problem/G 题意: 给每位司机分配一个白天和晚上的行车路线, ...
- UVA11389 The Bus Driver Problem
题意:有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线.给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d*r.问如何分配路线才能使加班费最少. 贪心 ...
- UVA 11389(贪心问题)
UVA 11389 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description II ...
- UVA 10245 The Closest Pair Problem 最近点问题 分治算法
题意,给出n个点的坐标,找出两点间最近的距离,如果小于10000就输出INFINITY. 纯暴力是会超时的,所以得另辟蹊径,用分治算法. 递归思路将点按坐标排序后,分成两块处理,最近的距离不是在两块中 ...
- UVa 100 - The 3n + 1 problem(函数循环长度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
随机推荐
- iOS人脸识别(CoreImage)
1.从初始UIImage获取一个CIImage对象. 2.创建一个用于分析对象的CIContext. 3.通过type和options参数创建一个CIDetector实例. type参数指定了要识别的 ...
- iOS开发系列之触摸事件
基础知识 三类事件中触摸事件在iOS中是最常用的事件,这里我们首先介绍触摸事件. 在下面的例子中定义一个KCImage,它继承于UIView,在KCImage中指定一个图片作为背景.定义一个视图控制器 ...
- C#中的操作数据库的SQLHelper类
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- jQuery的选择器中的通配符[id^='code']或[name^='code']
这两天在做一个专题的时候遇到了一个通配符的问题 //弹层操作$(function(){ //视频播放 $("a[href^='#video']").each(function(in ...
- ASP.NET的WebConfig
转:http://blog.csdn.net/q3498233/article/details/8137364 WebConfig 花了点时间整理了一下ASP.NET Web.config配置文件的基 ...
- 编译安装php时提示Cannot find MySQL header files的解决方法
php的配置文件中有一行--with-mysql=/usr/local/mysql ,安装的时候提示:configure: error: Cannot find MySQL header files ...
- 【转】 iOS使用AVFoundation实现二维码扫描
原文:http://strivingboy.github.io/blog/2014/11/08/scan-qrcode/ 关于二维码扫描有不少优秀第三方库如: ZBar SDK 里面有详细的文档,相应 ...
- Android之声音管理器《AudioManager》的使用以及音量控制
以下为网上下载然后拼接-- Android声音管理AudioManager使用 手机都有声音模式,声音.静音还有震动,甚至震动加声音兼备,这些都是手机的基本功能.在Android手机中,我们同样可以通 ...
- svn更新
下载配置文件 pwd cd /home/www/xxxx/protected/config/ get main.php 上传配置文件 put main.php svn更新 svn co svn://s ...
- underscorejs-sortBy学习
2.17 sortBy 2.17.1 语法 _.sortBy(list, iteratee, [context]) 2.17.2 说明 返回一个排序后的list拷贝副本. list为集合,如数组.对象 ...