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 ...
随机推荐
- Qt应用中检测内存泄露——VLD
本文简要描述一下在Qt应用中使用VLD来检测内存泄露.本次测试环境:QtCreator2.3 + Qt4.7.4-vs2008 + VS2008 Express. 1.下载并安装:VLD-2.2: h ...
- RunTime 应用实例–关于埋点的思考
埋点是现在很多App中都需要用到的,这个问题可能每个人都能处理,但是怎样来减少埋点所带来的侵入性,怎样用更加简洁的方式来处理埋点问题,怎样减少误埋,如果上线了发现少埋了怎么办?下面是本文讨论的重点: ...
- Android(java)学习笔记241:多媒体之 MediaPlayer使用
MediaPlayer类可用于控制音频/视频文件或流的播放.关于如何使用这个类的方法还可以阅读VideoView类的文档. 1.MediaPlayer 状态图 对播放音频/视频文件和流的控 ...
- 转载:C# HashSet 用法
原文地址:http://www.cnblogs.com/xiaopin/archive/2011/01/08/1930540.html 感谢博主分享! NET 3.5在System.Collect ...
- 11、SQL Server 视图、数据库快照
SQL Server 视图 什么是视图? 视图是一个虚拟的表,内容源于查询的结果集.只有当视图上建立了索引后,才会具体化. 视图可以筛选和处理数据,而不是直接访问基础表.如:创建一个视图,只展示源表中 ...
- java中对象的转型
1.对象的向上转型——将子类的对象赋值给父类的引用 Student s=new Student(); Person p=s; 一个引用能够调哪些成员(变量和函数),取决于这个引用的类型 也就是Pe ...
- 关于IO学习的几个函数
这是最近学到的几个关于IO文件操作的几个小算法,今天总结出来. 1. 删除一个给定的目录,这上目录不为空目录,使用递归来实现 public void test04(File file) { File[ ...
- 使用mailto在网页中链接Email地址
<a>标签还有一个作用是可以链接Email地址,使用mailto能让访问者便捷向网站管理者发送电子邮件.我们还可以利用mailto做许多其它事情.下面一一进行讲解,请看详细图示: 注意:如 ...
- [JS] save txt file
(function () { var blob = new Blob(['content'], {type: 'text/plain; charset=utf-8'}), blobUrl = URL. ...
- Fractal_Test
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Fractal_Test.html 参考:http://catlikecoding ...