General Problem Solving Techniques [Intermediate-1]~G - The Bus Driver Problem
2015-10-09 21:40
459 查看
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个司机,每个司机都有相同的路程分配量,且每个司机都要上午和下午各开一次车。要求怎样分配才能使司机的加班费用最少,可以考虑贪心,平均分配。使得每个司机都能开一次长路程和短路程(相对情况下)。
程序代码:
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\n",sum*r); } return 0; }
相关文章推荐
- [LeetCode]20. Unique Paths II唯一路径
- 【Foundation-86-3】#import <Foundation/NSValue.h> 初始化
- UINavigationController+storyboard
- General Problem Solving Techniques [Intermediate-1]~F - Tian Ji -- The Horse Racing
- 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
- iOS:UIResponser控件的介绍(响应者)
- BestCoder 1st Anniversary ($) HDU5312 Sequence
- builder模式
- SPOJ Query on a tree (树链剖分 + 线段树)
- 浅谈UIScrollView的用法
- 【Foundation-86-2】#import <Foundation/NSValue.h>
- UESTC 86 Divide(贪心+二进制)
- 几种键盘回收方式
- General Problem Solving Techniques [Intermediate-1]~E - The Trip, 2007
- POJ 3017 Cut the Sequence (单调队列优化DP)
- UINavigationController
- UESTC 84 Binary Operations(位运算+DP)
- [LeetCode]19. Unique Paths唯一路径
- TestDataBuilder自动生成工具
- UE4高级功能-初探超大无缝map的实现LevelStream